From c2d9e366d1c1ef1eaf0d30f66b6c4a9affe09d67 Mon Sep 17 00:00:00 2001 From: Mohamed Nouffer Date: Mon, 11 Sep 2023 00:45:54 +0530 Subject: [PATCH] fixed state --- lib/main.dart | 35 +++++++++++-------- .../destination/destination_binding.dart | 2 ++ .../destination/destination_controller.dart | 22 +++++++++--- lib/pages/index/index_page.dart | 8 ++++- lib/widgets/bottom_sheet_new.dart | 21 ++++++++++- pubspec.yaml | 3 +- 6 files changed, 69 insertions(+), 22 deletions(-) diff --git a/lib/main.dart b/lib/main.dart index f8b9f3f..fcd5058 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -9,6 +9,21 @@ import 'package:rogapp/utils/string_values.dart'; import 'package:shared_preferences/shared_preferences.dart'; // import 'package:is_lock_screen/is_lock_screen.dart'; +void saveGameState() async { + DestinationController destinationController = Get.find(); + SharedPreferences pref = await SharedPreferences.getInstance(); + pref.setBool("is_in_rog", destinationController.is_in_rog.value); + pref.setBool("rogaining_counted", destinationController.rogaining_counted.value); + } + +void restoreGame() async{ + SharedPreferences pref = await SharedPreferences.getInstance(); + DestinationController destinationController = Get.find(); + destinationController.skip_gps = false; + destinationController.is_in_rog.value = pref.getBool("is_in_rog") ?? false; + destinationController.rogaining_counted.value = pref.getBool("rogaining_counted") ?? false; + } + void main() async { WidgetsFlutterBinding.ensureInitialized(); @@ -27,7 +42,6 @@ void main() async { key: 'behaviour', value: 'cacheFirst', ); - runApp(const MyApp()); } @@ -55,20 +69,13 @@ class _MyAppState extends State with WidgetsBindingObserver { super.dispose(); } - void saveGameState() async { - DestinationController destinationController = Get.find(); - SharedPreferences pref = await SharedPreferences.getInstance(); - pref.setBool("is_in_rog", destinationController.is_in_rog.value); - pref.setBool("rogaining_counted", destinationController.rogaining_counted.value); - } + // void saveGameState() async { + // DestinationController destinationController = Get.find(); + // SharedPreferences pref = await SharedPreferences.getInstance(); + // pref.setBool("is_in_rog", destinationController.is_in_rog.value); + // pref.setBool("rogaining_counted", destinationController.rogaining_counted.value); + // } - void restoreGame() async{ - SharedPreferences pref = await SharedPreferences.getInstance(); - DestinationController destinationController = Get.find(); - destinationController.skip_gps = false; - destinationController.is_in_rog.value = pref.getBool("is_in_rog") ?? false; - destinationController.rogaining_counted.value = pref.getBool("rogaining_counted") ?? false; - } void didChangeAppLifecycleState(AppLifecycleState state) { DestinationController destinationController = Get.find(); diff --git a/lib/pages/destination/destination_binding.dart b/lib/pages/destination/destination_binding.dart index 8fab747..56e214d 100644 --- a/lib/pages/destination/destination_binding.dart +++ b/lib/pages/destination/destination_binding.dart @@ -1,9 +1,11 @@ import 'package:get/get.dart'; +import 'package:rogapp/main.dart'; import 'package:rogapp/pages/destination/destination_controller.dart'; class DestinationBinding extends Bindings { @override void dependencies() { Get.put(DestinationController()); + restoreGame(); } } diff --git a/lib/pages/destination/destination_controller.dart b/lib/pages/destination/destination_controller.dart index 9aebfa1..5c63745 100644 --- a/lib/pages/destination/destination_controller.dart +++ b/lib/pages/destination/destination_controller.dart @@ -9,6 +9,7 @@ import 'package:geolocator/geolocator.dart'; import 'package:get/get.dart'; import 'package:intl/intl.dart'; import 'package:latlong2/latlong.dart'; +import 'package:rogapp/main.dart'; import 'package:rogapp/model/destination.dart'; import 'package:rogapp/pages/camera/camera_page.dart'; import 'package:rogapp/pages/index/index_controller.dart'; @@ -109,9 +110,10 @@ class DestinationController extends GetxController { void startTimerLocation(GeoJsonFeature fs, double distance) { print("---- in startTimer ----"); + print("---- is in rog is ${is_in_rog} ----"); //skip_gps = true; double checkinRadious = fs.properties!['checkin_radius'] ?? double.infinity; - if (checkinRadious >= distance) { + //if (checkinRadious >= distance) { indexController.currentFeature.clear(); Destination d = festuretoDestination(fs); print("----- destination lenght is ${destinations.length} -----"); @@ -124,7 +126,7 @@ class DestinationController extends GetxController { indexController.currentFeature.add(fs); print("---- before calling startTimer ----"); startTimer(d, distance); - } + //} } void startTimer(Destination d, double distance) async { @@ -337,6 +339,8 @@ class DestinationController extends GetxController { is_gps_selected.value = true; skip_gps = false; + saveGameState(); + _start = 0; chekcs = 0; rogaining_counted.value = false; @@ -365,13 +369,16 @@ class DestinationController extends GetxController { context, MaterialPageRoute( builder: (_) => CameraCamera( + resolutionPreset: ResolutionPreset.medium, onFile: (file) { photos.add(file); Navigator.pop(context); print("----image file is : $file----"); //setState(() {}); }, - ))); + ) + + )); } void getRoutePoints() { @@ -408,6 +415,7 @@ class DestinationController extends GetxController { } else { print("--- hidden loc ${d.hidden_location} ----"); // ask for checkin + print("is rog ---- ${is_in_rog.value} ----"); if (d.hidden_location != null && d.hidden_location == 0 && is_in_rog.value == true && @@ -425,7 +433,7 @@ class DestinationController extends GetxController { destination: d, ))).whenComplete(() { skip_gps = false; - rogaining_counted.value = true; + //rogaining_counted.value = true; chekcs = 0; is_in_checkin.value = false; }); @@ -497,6 +505,8 @@ class DestinationController extends GetxController { makeCheckin(df, true, ""); } is_in_rog.value = true; + + saveGameState(); } void makeCheckin( @@ -514,7 +524,7 @@ class DestinationController extends GetxController { await GallerySaver.saveImage(imageurl); - PopulateDestinations(); + //PopulateDestinations(); /// post to NATNAT if (indexController.currentUser.isNotEmpty) { @@ -622,6 +632,8 @@ class DestinationController extends GetxController { // Start a new timer that fires every 3 seconds _timer = Timer.periodic(Duration(seconds: 3), (timer) async { Position position = await Geolocator.getCurrentPosition(desiredAccuracy: LocationAccuracy.high); + current_lat = position.latitude; + current_lon = position.longitude; if (is_gps_selected.value) { double czoom = indexController.rogMapController.zoom; diff --git a/lib/pages/index/index_page.dart b/lib/pages/index/index_page.dart index 14d54cc..69526fd 100644 --- a/lib/pages/index/index_page.dart +++ b/lib/pages/index/index_page.dart @@ -65,8 +65,14 @@ class IndexPage extends GetView { ), bottomNavigationBar: BottomAppBar( child: Row( - mainAxisAlignment: MainAxisAlignment.end, + mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ + Obx(() => + destinationController.is_in_rog.value == true ? + IconButton(onPressed: (){}, icon: Icon(Icons.run_circle, size: 44, color: Colors.green,)) + : + IconButton(onPressed: (){}, icon: Icon(Icons.run_circle, size: 44, color: Colors.black12,)), + ), Padding( padding: const EdgeInsets.only(right: 10.0, top: 4.0, bottom: 4.0), diff --git a/lib/widgets/bottom_sheet_new.dart b/lib/widgets/bottom_sheet_new.dart index 0719d9b..a124cd4 100644 --- a/lib/widgets/bottom_sheet_new.dart +++ b/lib/widgets/bottom_sheet_new.dart @@ -3,6 +3,8 @@ import 'package:geojson/geojson.dart'; import 'package:geolocator/geolocator.dart'; import 'package:get/get.dart'; import 'package:image_picker/image_picker.dart'; +import 'package:latlong2/latlong.dart'; +import 'package:rogapp/main.dart'; import 'package:rogapp/model/destination.dart'; import 'package:rogapp/pages/destination/destination_controller.dart'; import 'package:rogapp/pages/index/index_controller.dart'; @@ -242,6 +244,7 @@ class BottomSheetNew extends GetView { destinationController.current_lon, indexController .currentDestinationFeature[0].location_id!); + saveGameState(); ExternalService() .StartRogaining() .then((value) => Get.back()); @@ -368,6 +371,13 @@ class BottomSheetNew extends GetView { // show add location details SingleChildScrollView detailsSheet(BuildContext context) { + + Destination _cdest = destinationController.festuretoDestination( + indexController.currentFeature[0]); + var distance = const Distance(); + double _distance_to_dest = distance.as(LengthUnit.Meter, LatLng(destinationController.current_lat, destinationController.current_lon), LatLng(_cdest.lat!, _cdest.lon!)); + + return SingleChildScrollView( child: Column( children: [ @@ -445,6 +455,7 @@ class BottomSheetNew extends GetView { indexController .currentDestinationFeature[0] .location_id!); + saveGameState(); ExternalService() .StartRogaining() .then((value) => Get.back()); @@ -535,6 +546,10 @@ class BottomSheetNew extends GetView { SizedBox( width: 10, ), + + + // forced start / checkin + _distance_to_dest <= 100 ? ElevatedButton( style: ElevatedButton.styleFrom( backgroundColor: @@ -550,6 +565,7 @@ class BottomSheetNew extends GetView { destinationController.current_lat, destinationController.current_lon, dd.location_id!); + saveGameState(); ExternalService() .StartRogaining() .then((value) => Get.back()); @@ -569,7 +585,10 @@ class BottomSheetNew extends GetView { style: TextStyle( color: Theme.of(context) .colorScheme - .onSecondary))), + .onSecondary))): + + Container() + , ], ), Row( diff --git a/pubspec.yaml b/pubspec.yaml index 2996a7f..42c2006 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -69,7 +69,7 @@ dependencies: flutter_launcher_icons: ^0.13.1 rename: ^2.0.1 circular_menu: ^2.0.1 - camera_camera: ^3.0.0-dev + camera_camera: ^3.0.0 intl: ^0.18.1 modal_bottom_sheet: ^3.0.0-pre connectivity_plus: ^4.0.2 @@ -78,6 +78,7 @@ dependencies: gallery_saver: ^2.3.2 flutter_riverpod: ^2.4.0 + flutter_icons: android: true