fix : twice back press for exit application on live stock

This commit is contained in:
2025-08-25 09:56:50 +03:30
parent 80e3b01998
commit 3bd3ecbf50
4 changed files with 37 additions and 33 deletions

View File

@@ -67,7 +67,6 @@ class MapWidgetLogic extends GetxController with GetTickerProviderStateMixin {
super.onReady(); super.onReady();
determineCurrentPosition(); determineCurrentPosition();
getLoc(); getLoc();
} }
@override @override
@@ -189,13 +188,12 @@ class MapWidgetLogic extends GetxController with GetTickerProviderStateMixin {
final newLat = currentPosition.latitude + (dy / 111000.0); final newLat = currentPosition.latitude + (dy / 111000.0);
// 1 درجه lon ≈ 111km * cos(lat) // 1 درجه lon ≈ 111km * cos(lat)
final newLng = currentPosition.longitude + final newLng =
(dx / (111000.0 * cos(currentPosition.latitude * pi / 180))); currentPosition.longitude + (dx / (111000.0 * cos(currentPosition.latitude * pi / 180)));
locations.add(LatLng(newLat, newLng)); locations.add(LatLng(newLat, newLng));
} }
return locations; return locations;
} }
} }

View File

@@ -3,9 +3,6 @@ import 'dart:math';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:rasadyar_core/core.dart'; import 'package:rasadyar_core/core.dart';
import 'package:rasadyar_livestock/data/repository/livestock/livestock_repository.dart';
import 'package:rasadyar_livestock/data/repository/livestock/livestock_repository_imp.dart';
import 'package:rasadyar_livestock/injection/live_stock_di.dart';
import 'package:rasadyar_livestock/presentation/page/map/view.dart'; import 'package:rasadyar_livestock/presentation/page/map/view.dart';
import 'package:rasadyar_livestock/presentation/page/profile/view.dart'; import 'package:rasadyar_livestock/presentation/page/profile/view.dart';
import 'package:rasadyar_livestock/presentation/page/request_tagging/view.dart'; import 'package:rasadyar_livestock/presentation/page/request_tagging/view.dart';
@@ -14,9 +11,13 @@ import 'package:rasadyar_livestock/presentation/routes/app_pages.dart';
class RootLogic extends GetxController { class RootLogic extends GetxController {
List<Widget> pages = [ List<Widget> pages = [
MapPage(),
Navigator( Navigator(
key: Get.nestedKey(0), key: Get.nestedKey(0),
onGenerateRoute: (settings) => GetPageRoute(page: () => MapPage()),
),
Navigator(
key: Get.nestedKey(1),
initialRoute: LiveStockRoutes.requests, initialRoute: LiveStockRoutes.requests,
onGenerateRoute: (settings) { onGenerateRoute: (settings) {
switch (settings.name) { switch (settings.name) {
@@ -30,7 +31,10 @@ class RootLogic extends GetxController {
}, },
), ),
ProfilePage(), Navigator(
key: Get.nestedKey(2),
onGenerateRoute: (settings) => GetPageRoute(page: () => ProfilePage()),
),
]; ];
RxInt currentIndex = 0.obs; RxInt currentIndex = 0.obs;
@@ -48,7 +52,7 @@ class RootLogic extends GetxController {
} }
}); });
/* GetIt.instance.allReady().then((value) async { /* GetIt.instance.allReady().then((value) async {
await diLiveStock.get<LivestockRepositoryImp>().addLocations(generateRandomPoints()); await diLiveStock.get<LivestockRepositoryImp>().addLocations(generateRandomPoints());
});*/ });*/
} }

View File

@@ -1,40 +1,41 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:rasadyar_core/core.dart'; import 'package:rasadyar_core/core.dart';
import 'logic.dart'; import 'logic.dart';
class RootPage extends GetView<RootLogic> { class RootPage extends GetView<RootLogic> {
const RootPage({super.key}); RootPage({super.key});
DateTime? _lastBackPressed;
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return ObxValue((currentIndex) { return ObxValue((currentIndex) {
return PopScope( return PopScope(
canPop: false, canPop: false,
onPopInvokedWithResult: (didPop, result) { onPopInvokedWithResult: (didPop, result) async {
final navigatorKey = Get.nestedKey(currentIndex); final nestedKey = Get.nestedKey(controller.currentIndex.value);
eLog('Pop invoked with result: $result, didPop: $didPop'); final currentNavigator = nestedKey?.currentState;
navigatorKey?.currentState?.pop();
/*eLog('Pop invoked with result: $result, didPop: $didPop'); if (currentNavigator?.canPop() ?? false) {
iLog(Get.currentRoute); currentNavigator?.pop();
iLog(Get.previousRoute); } else {
final now = DateTime.now();
final navigatorKey = Get.nestedKey(currentIndex); if (_lastBackPressed == null ||
now.difference(_lastBackPressed!) > Duration(seconds: 2)) {
if (currentIndex.value == 0 && _lastBackPressed = now;
Get.snackbar(
navigatorKey != null && 'خروج از برنامه',
navigatorKey.currentState != null) { 'برای خروج دوباره بازگشت را بزنید',
if (navigatorKey.currentState!.canPop()) { snackPosition: SnackPosition.TOP,
navigatorKey.currentState!.pop(); duration: Duration(seconds: 2),
return; backgroundColor: AppColor.warning,
);
} else {
await SystemNavigator.pop();
} }
}
if (!didPop) {
return;
}
}*/
}, },
child: Scaffold( child: Scaffold(

View File

@@ -6,6 +6,7 @@ sealed class LiveStockRoutes {
static const auth = '/AuthLiveStock'; static const auth = '/AuthLiveStock';
static const init = '/liveStock'; static const init = '/liveStock';
static const requests = '/requests'; static const requests = '/requests';
static const map = '/map';
static const profile = '/profile'; static const profile = '/profile';
//static const requestTagging = '$init/tagging'; //static const requestTagging = '$init/tagging';