diff --git a/lib/backend/DataManager.dart b/lib/backend/DataManager.dart index 767176b..fdeb80e 100644 --- a/lib/backend/DataManager.dart +++ b/lib/backend/DataManager.dart @@ -17,6 +17,18 @@ class DataManager{ static dynamic UserJson; + static dynamic cryptoRates; + static double currentEarnings =0; + static Map GamesEarnings = {}; + static Map CryptoEarnings = {}; + + + static void Reset(){ + UserJson = LinkedGamesJson = NonLinkedGamesJson = Challenges = []; + currentEarnings = 0; + GamesEarnings = CryptoEarnings = {}; + } + static Future Init() async{ bool isSettingsDone = await GetSettings(); bool isGamesDone = await GetGames(); @@ -43,31 +55,35 @@ class DataManager{ } static void FilterLinkedGames(){ - LinkedGamesJson = []; - NonLinkedGamesJson = []; - if(UserJson['linkedGames'].toString().length < 3){ - NonLinkedGamesJson = AllGames; - return; - } - List> linkedGames = jsonDecode( - UserJson['linkedGames']).cast>(); + Debug.Log("err044 : $UserJson"); + LinkedGamesJson = []; + NonLinkedGamesJson = []; + if (UserJson['linkedGames'] + .toString() + .length < 3) { + NonLinkedGamesJson = AllGames; + return; + } + List> linkedGames = jsonDecode( + UserJson['linkedGames']).cast>(); - AllGames.forEach((element) { - bool foundLink = false; - for (var linkedGame in linkedGames) { - int gid = linkedGame["game_id"]; - int id = int.parse(element['id']); - if (gid == id) { - LinkedGamesJson.add(element); - foundLink = true; - break; + AllGames.forEach((element) { + bool foundLink = false; + for (var linkedGame in linkedGames) { + int gid = linkedGame["game_id"]; + int id = int.parse(element['id']); + if (gid == id) { + LinkedGamesJson.add(element); + foundLink = true; + break; + } } - } - if (!foundLink) { - NonLinkedGamesJson.add(element); - } - }); + if (!foundLink) { + NonLinkedGamesJson.add(element); + } + }); + } static Future GetSettings() async{ @@ -143,10 +159,7 @@ class DataManager{ Challenges = _Challenges; return true; } - static dynamic cryptoRates; - static double currentEarnings =0; - static Map GamesEarnings = {}; - static Map CryptoEarnings = {}; + static void CalculateEarnings() async{ @@ -215,4 +228,6 @@ class DataManager{ Debug.LogError(e); } } + + } \ No newline at end of file diff --git a/lib/home.dart b/lib/home.dart index 43be77c..1894f9e 100644 --- a/lib/home.dart +++ b/lib/home.dart @@ -525,6 +525,7 @@ class _HomeState extends State { Navigator.of(context).pushAndRemoveUntil(MaterialPageRoute(builder: (context) => MyHomePage()), (Route route) => false); + DataManager.Reset(); }, child: GlassCard(child: Padding( padding: const EdgeInsets.all(15.0), diff --git a/lib/welcome.dart b/lib/welcome.dart index ea0cd5c..e715c54 100644 --- a/lib/welcome.dart +++ b/lib/welcome.dart @@ -200,7 +200,9 @@ class _MyHomePageState extends State { int regResult = await LoginManager.Register(usernameController.text, passwordController.text); if(regResult == 0){ + await LoginManager.AutoLogin(); await DataManager.GetGamesProgress(); + loadHome(); }else if(regResult == 5){ Dialogs.showAlertDialog(context, "Register Failed", "Username Already exists, Please try again with a different username");