optimized

This commit is contained in:
Mohamed Nouffer
2023-10-06 16:25:21 +05:30
parent 7fdb6c05ee
commit 0e2a8f89f3
101 changed files with 50948 additions and 4137 deletions

View File

@ -3,26 +3,29 @@ import 'package:flutter_map_tile_caching/flutter_map_tile_caching.dart';
import 'package:get/get.dart';
import 'package:rogapp/pages/destination/destination_controller.dart';
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 saveGameState() async {
DestinationController destinationController = Get.find<DestinationController>();
SharedPreferences pref = await SharedPreferences.getInstance();
pref.setBool("is_in_rog", destinationController.is_in_rog.value);
pref.setBool("rogaining_counted", destinationController.rogaining_counted.value);
}
DestinationController destinationController =
Get.find<DestinationController>();
SharedPreferences pref = await SharedPreferences.getInstance();
pref.setBool("is_in_rog", destinationController.isInRog.value);
pref.setBool(
"rogaining_counted", destinationController.rogainingCounted.value);
}
void restoreGame() async{
SharedPreferences pref = await SharedPreferences.getInstance();
DestinationController destinationController = Get.find<DestinationController>();
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 restoreGame() async {
SharedPreferences pref = await SharedPreferences.getInstance();
DestinationController destinationController =
Get.find<DestinationController>();
destinationController.skipGps = false;
destinationController.isInRog.value = pref.getBool("is_in_rog") ?? false;
destinationController.rogainingCounted.value =
pref.getBool("rogaining_counted") ?? false;
}
void main() async {
WidgetsFlutterBinding.ensureInitialized();
@ -61,8 +64,6 @@ class _MyAppState extends State<MyApp> with WidgetsBindingObserver {
WidgetsBinding.instance.addObserver(this);
}
@override
void dispose() {
WidgetsBinding.instance.removeObserver(this);
@ -76,35 +77,36 @@ class _MyAppState extends State<MyApp> with WidgetsBindingObserver {
// pref.setBool("rogaining_counted", destinationController.rogaining_counted.value);
// }
@override
void didChangeAppLifecycleState(AppLifecycleState state) {
DestinationController destinationController = Get.find<DestinationController>();
switch (state) {
case AppLifecycleState.resumed:
print("RESUMED");
restoreGame();
if(destinationController.positionStream == null){
destinationController.startGPSTimer();
//destinationController.startGame();
}
break;
case AppLifecycleState.inactive:
print("INACTIVE");
break;
case AppLifecycleState.paused:
print("PAUSED");
saveGameState();
break;
case AppLifecycleState.detached:
print("DETACHED");
saveGameState();
break;
case AppLifecycleState.hidden:
print("DETACHED");
saveGameState();
break;
}
DestinationController destinationController =
Get.find<DestinationController>();
switch (state) {
case AppLifecycleState.resumed:
//print("RESUMED");
restoreGame();
if (destinationController.positionStream == null) {
//destinationController.startGPSTimer();
//destinationController.startGame();
}
break;
case AppLifecycleState.inactive:
//print("INACTIVE");
break;
case AppLifecycleState.paused:
//print("PAUSED");
saveGameState();
break;
case AppLifecycleState.detached:
//print("DETACHED");
saveGameState();
break;
case AppLifecycleState.hidden:
//print("DETACHED");
saveGameState();
break;
}
}
@override
Widget build(BuildContext context) {
@ -115,8 +117,8 @@ class _MyAppState extends State<MyApp> with WidgetsBindingObserver {
fallbackLocale: const Locale('en', 'US'),
title: 'ROGAINING',
theme: ThemeData(
colorScheme:
ColorScheme.fromSeed(seedColor: Color.fromARGB(255, 36, 135, 221)),
colorScheme: ColorScheme.fromSeed(
seedColor: const Color.fromARGB(255, 36, 135, 221)),
useMaterial3: true,
),
debugShowCheckedModeBanner: false,
@ -131,51 +133,3 @@ class _MyAppState extends State<MyApp> with WidgetsBindingObserver {
);
}
}
// class MyApp extends StatelessWidget {
// MyApp({Key? key}) : super(key: key);
// // This widget is the root of your application.
// @override
// Widget build(BuildContext context) {
// return MaterialApp(
// title: 'Flutter Demo',
// theme: ThemeData(
// primaryColor: Color(0xfff00B074),
// textTheme: const TextTheme(
// bodyText1: TextStyle(
// fontSize: 18.0,
// fontFamily: 'Barlow-Medium',
// color: Color(0xff464255)),
// ),
// ),
// home: PermissionHandlerScreen(),
// );
// }
// }
// class SplashScreen extends StatelessWidget {
// const SplashScreen({Key? key}) : super(key: key);
// @override
// Widget build(BuildContext context) {
// return WillPopScope(
// onWillPop: () async {
// SystemNavigator.pop();
// return true;
// },
// child: Scaffold(
// body: Center(
// child: Text(
// "Splash Screen",
// ),
// ),
// ),
// );
// }
// }