From 6f3249631f0021acb00aaf99618f6c44a72853f9 Mon Sep 17 00:00:00 2001 From: Mohamed Nouffer Date: Fri, 8 Sep 2023 21:19:12 +0530 Subject: [PATCH] update status --- ios/Podfile.lock | 6 ++ ios/Runner.xcodeproj/project.pbxproj | 6 +- lib/main.dart | 22 +++++- lib/model/game_instance_state.dart | 18 +++++ .../destination/destination_controller.dart | 67 ++++++++++--------- lib/provider/game_state_provider.dart | 27 ++++++++ pubspec.lock | 24 +++++++ pubspec.yaml | 1 + 8 files changed, 135 insertions(+), 36 deletions(-) create mode 100644 lib/model/game_instance_state.dart create mode 100644 lib/provider/game_state_provider.dart diff --git a/ios/Podfile.lock b/ios/Podfile.lock index 07d74b1..810d910 100644 --- a/ios/Podfile.lock +++ b/ios/Podfile.lock @@ -12,6 +12,8 @@ PODS: - FMDB (2.7.5): - FMDB/standard (= 2.7.5) - FMDB/standard (2.7.5) + - gallery_saver (0.0.1): + - Flutter - geolocator_apple (1.2.0): - Flutter - google_maps_flutter_ios (0.0.1): @@ -47,6 +49,7 @@ DEPENDENCIES: - Flutter (from `Flutter`) - flutter_compass (from `.symlinks/plugins/flutter_compass/ios`) - flutter_keyboard_visibility (from `.symlinks/plugins/flutter_keyboard_visibility/ios`) + - gallery_saver (from `.symlinks/plugins/gallery_saver/ios`) - geolocator_apple (from `.symlinks/plugins/geolocator_apple/ios`) - google_maps_flutter_ios (from `.symlinks/plugins/google_maps_flutter_ios/ios`) - image_picker_ios (from `.symlinks/plugins/image_picker_ios/ios`) @@ -74,6 +77,8 @@ EXTERNAL SOURCES: :path: ".symlinks/plugins/flutter_compass/ios" flutter_keyboard_visibility: :path: ".symlinks/plugins/flutter_keyboard_visibility/ios" + gallery_saver: + :path: ".symlinks/plugins/gallery_saver/ios" geolocator_apple: :path: ".symlinks/plugins/geolocator_apple/ios" google_maps_flutter_ios: @@ -100,6 +105,7 @@ SPEC CHECKSUMS: flutter_compass: cbbd285cea1584c7ac9c4e0c3e1f17cbea55e855 flutter_keyboard_visibility: 0339d06371254c3eb25eeb90ba8d17dca8f9c069 FMDB: 2ce00b547f966261cd18927a3ddb07cb6f3db82a + gallery_saver: 9fc173c9f4fcc48af53b2a9ebea1b643255be542 geolocator_apple: cc556e6844d508c95df1e87e3ea6fa4e58c50401 google_maps_flutter_ios: abdac20d6ce8931f6ebc5f46616df241bfaa2cfd GoogleMaps: 025272d5876d3b32604e5c080dc25eaf68764693 diff --git a/ios/Runner.xcodeproj/project.pbxproj b/ios/Runner.xcodeproj/project.pbxproj index 4dc0f41..15d5f73 100644 --- a/ios/Runner.xcodeproj/project.pbxproj +++ b/ios/Runner.xcodeproj/project.pbxproj @@ -376,7 +376,7 @@ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CLANG_ENABLE_MODULES = YES; CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)"; - DEVELOPMENT_TEAM = D5SL68ATB9; + DEVELOPMENT_TEAM = ECMVJVB7LV; ENABLE_BITCODE = NO; INFOPLIST_FILE = Runner/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 12.0; @@ -506,7 +506,7 @@ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CLANG_ENABLE_MODULES = YES; CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)"; - DEVELOPMENT_TEAM = D5SL68ATB9; + DEVELOPMENT_TEAM = ECMVJVB7LV; ENABLE_BITCODE = NO; INFOPLIST_FILE = Runner/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 12.0; @@ -530,7 +530,7 @@ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CLANG_ENABLE_MODULES = YES; CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)"; - DEVELOPMENT_TEAM = D5SL68ATB9; + DEVELOPMENT_TEAM = ECMVJVB7LV; ENABLE_BITCODE = NO; INFOPLIST_FILE = Runner/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 12.0; diff --git a/lib/main.dart b/lib/main.dart index 49a4c7e..f8b9f3f 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -6,6 +6,7 @@ import 'package:rogapp/pages/index/index_binding.dart'; import 'package:rogapp/pages/index/index_controller.dart'; import 'package:rogapp/routes/app_pages.dart'; import 'package:rogapp/utils/string_values.dart'; +import 'package:shared_preferences/shared_preferences.dart'; // import 'package:is_lock_screen/is_lock_screen.dart'; void main() async { @@ -54,11 +55,27 @@ 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 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(); switch (state) { case AppLifecycleState.resumed: print("RESUMED"); - DestinationController destinationController = Get.find(); + restoreGame(); if(destinationController.positionStream == null){ destinationController.startGPSTimer(); } @@ -68,12 +85,15 @@ class _MyAppState extends State with WidgetsBindingObserver { break; case AppLifecycleState.paused: print("PAUSED"); + saveGameState(); break; case AppLifecycleState.detached: print("DETACHED"); + saveGameState(); break; case AppLifecycleState.hidden: print("DETACHED"); + saveGameState(); break; } } diff --git a/lib/model/game_instance_state.dart b/lib/model/game_instance_state.dart new file mode 100644 index 0000000..c0b9f06 --- /dev/null +++ b/lib/model/game_instance_state.dart @@ -0,0 +1,18 @@ +enum LocationState { + noGps, + notInCheckin, + withinCheckin + } + + enum GameState { + notStarted, + startedNotCounted, + startedCounted, + nodeGoal + } + + +class GameInstanceState{ + LocationState locationState = LocationState.noGps; + GameState gameState = GameState.notStarted; +} \ No newline at end of file diff --git a/lib/pages/destination/destination_controller.dart b/lib/pages/destination/destination_controller.dart index 21b2ab9..9aebfa1 100644 --- a/lib/pages/destination/destination_controller.dart +++ b/lib/pages/destination/destination_controller.dart @@ -114,12 +114,13 @@ class DestinationController extends GetxController { if (checkinRadious >= distance) { indexController.currentFeature.clear(); Destination d = festuretoDestination(fs); - for (Destination de in destinations) { - if (de.location_id == d.location_id) { - d = de; - break; - } - } + print("----- destination lenght is ${destinations.length} -----"); + // for (Destination de in destinations) { + // if (de.location_id == d.location_id) { + // d = de; + // break; + // } + // } indexController.currentFeature.add(fs); print("---- before calling startTimer ----"); startTimer(d, distance); @@ -130,9 +131,13 @@ class DestinationController extends GetxController { print("=== passed dest is ${d.location_id} ${d.checkedin} ===="); skip_gps = true; print("---- in startTimer ----"); + + DatabaseHelper db = DatabaseHelper.instance; + List ds = await db.getDestinationByLatLon(d.lat!, d.lon!); + double checkinRadious = d.checkin_radious ?? double.infinity; bool autoCheckin = d.auto_checkin == 0 ? false : true; - bool locationAlreadyCheckedIn = d.checkedin ?? false; + bool locationAlreadyCheckedIn = ds.length > 0 && ds[0].checkedin == true ? true : false; bool isuserLoggedIn = indexController.currentUser.isNotEmpty ? true : false; //make current destination print("---- checkin_radious $checkinRadious ----"); @@ -165,8 +170,6 @@ class DestinationController extends GetxController { return; } - DatabaseHelper db = DatabaseHelper.instance; - List ds = await db.getDestinationByLatLon(d.lat!, d.lon!); if (ds.isEmpty) { print("----- in location popup cp - ${d.cp}----"); if (d.cp == -1 && DateTime.now().difference(last_goal_at).inHours >= 24) { @@ -435,32 +438,32 @@ class DestinationController extends GetxController { void checkForCheckin(double la, double ln) { print("--- skip_gps ---- $skip_gps----"); - for (final d in destinations) { - print("--- check checkin for--loc_id- ${d.sub_loc_id}----"); + // for (final d in destinations) { + // print("--- check checkin for--loc_id- ${d.sub_loc_id}----"); - double lat = d.lat!; - double lon = d.lon!; - LatLng p = LatLng(lat, lon); - getDestinationForLatLong(lat, lon).then((value) { - var distance = const Distance(); - double dist = - distance.as(LengthUnit.Meter, LatLng(lat, lon), LatLng(la, ln)); - //double checkin_radious = value!.checkin_radious ?? double.infinity; - //bool auto_checkin = value.auto_checkin == 0 ? false : true; - //bool location_already_checked_id = d.checkedin ?? false; + // double lat = d.lat!; + // double lon = d.lon!; + // LatLng p = LatLng(lat, lon); + // getDestinationForLatLong(lat, lon).then((value) { + // var distance = const Distance(); + // double dist = + // distance.as(LengthUnit.Meter, LatLng(lat, lon), LatLng(la, ln)); + // //double checkin_radious = value!.checkin_radious ?? double.infinity; + // //bool auto_checkin = value.auto_checkin == 0 ? false : true; + // //bool location_already_checked_id = d.checkedin ?? false; - // print("-----rogaining_counted---${rogaining_counted.value}-----"); - // print("-----is_in_rog---${is_in_rog}-----"); - // print("-----dist is ---${dist}-----"); - //print("----- ${indexController.currentUser} ----"); + // // print("-----rogaining_counted---${rogaining_counted.value}-----"); + // // print("-----is_in_rog---${is_in_rog}-----"); + // // print("-----dist is ---${dist}-----"); + // //print("----- ${indexController.currentUser} ----"); - if (dist <= 250 && skip_gps == false) { - //near a destination - print("---- time with ${d.location_id} ----"); - startTimer(d, dist); - } - }); - } + // if (dist <= 250 && skip_gps == false) { + // //near a destination + // print("---- time with ${d.location_id} ----"); + // startTimer(d, dist); + // } + // }); + // } if (indexController.locations.isEmpty) return; diff --git a/lib/provider/game_state_provider.dart b/lib/provider/game_state_provider.dart new file mode 100644 index 0000000..fe65635 --- /dev/null +++ b/lib/provider/game_state_provider.dart @@ -0,0 +1,27 @@ +import 'package:flutter_riverpod/flutter_riverpod.dart'; +import 'package:rogapp/model/game_instance_state.dart'; + +final gameStateNotifierProvider = StateNotifierProvider((ref) { + return GameStaticState(); +}); + + +class GameStaticState extends StateNotifier{ + GameStaticState(): super(GameInstanceState()); + + @override + GameInstanceState get state => super.state; + + void startGame(GameInstanceState gi){ + state = gi; + } + + void doCheckin(){ + + } + + void makeGoal(){ + + } + +} \ No newline at end of file diff --git a/pubspec.lock b/pubspec.lock index 5604da5..6e44faf 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -414,6 +414,14 @@ packages: url: "https://pub.dev" source: hosted version: "1.0.0" + flutter_riverpod: + dependency: "direct main" + description: + name: flutter_riverpod + sha256: "1bd39b04f1bcd217a969589777ca6bd642d116e3e5de65c3e6a8e8bdd8b178ec" + url: "https://pub.dev" + source: hosted + version: "2.4.0" flutter_test: dependency: "direct dev" description: flutter @@ -1080,6 +1088,14 @@ packages: url: "https://pub.dev" source: hosted version: "2.1.1" + riverpod: + dependency: transitive + description: + name: riverpod + sha256: a600120d6f213a9922860eea1abc32597436edd5b2c4e73b91410f8c2af67d22 + url: "https://pub.dev" + source: hosted + version: "2.4.0" sanitize_html: dependency: transitive description: @@ -1189,6 +1205,14 @@ packages: url: "https://pub.dev" source: hosted version: "1.11.0" + state_notifier: + dependency: transitive + description: + name: state_notifier + sha256: b8677376aa54f2d7c58280d5a007f9e8774f1968d1fb1c096adcb4792fba29bb + url: "https://pub.dev" + source: hosted + version: "1.0.0" stream_channel: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index e332a07..2996a7f 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -76,6 +76,7 @@ dependencies: flutter_map_tile_caching: ^8.0.1 shared_preferences: ^2.0.15 gallery_saver: ^2.3.2 + flutter_riverpod: ^2.4.0 flutter_icons: