From cb9bb2284572c8a1ddda98a60ce14c02a0b879a1 Mon Sep 17 00:00:00 2001 From: Nghia Nguyen Date: Mon, 24 Apr 2023 17:57:50 -0400 Subject: [PATCH] Learn and profile screens updated Learn screen doesn't show that it's loading and profile screen refreshed userpreferences when log out. --- app/lib/screens/LearnScreen.dart | 65 ++++++++++++++++++++++++------ app/lib/screens/ProfileScreen.dart | 15 +++---- 2 files changed, 61 insertions(+), 19 deletions(-) diff --git a/app/lib/screens/LearnScreen.dart b/app/lib/screens/LearnScreen.dart index e3252a9..b04aa5b 100644 --- a/app/lib/screens/LearnScreen.dart +++ b/app/lib/screens/LearnScreen.dart @@ -96,7 +96,9 @@ class LessonProgression extends StatefulWidget { class _LessonProgressionState extends State { int _index = 0; - late List _listOfStates; + List _listOfStates = UserPreferences.myUser.lessonProgress + .map((int num) => num == 0 ? StepState.indexed : StepState.complete) + .toList(); late bool _hasReminder; bool _dataFetched = false; @@ -109,12 +111,6 @@ class _LessonProgressionState extends State { - Stepstate.complete => The user already completed the lesson - Stepstate.indexed => The user has not already completed the lesson */ - UserPreferences.myUser.loadData().then((val) => { - _listOfStates = UserPreferences.myUser.lessonProgress - .map((int num) => - num == 0 ? StepState.indexed : StepState.complete) - .toList() - }); _hasReminder = false; UserPreferences.myUser.loadData().then((value) { @@ -181,11 +177,56 @@ class _LessonProgressionState extends State { }, steps: stepBuilder(_listOfStates), )) - : const Center( - child: Text( - 'Loading...', - textAlign: TextAlign.center, - )), + : Container( + padding: const EdgeInsets.fromLTRB(0, 0, 0, 80), + child: Stepper( + physics: const BouncingScrollPhysics(), + controlsBuilder: + (BuildContext context, ControlsDetails details) { + return Container( + padding: const EdgeInsets.only(top: 10.0), + alignment: Alignment.centerRight, + child: TextButton( + onPressed: details.onStepContinue, + style: ButtonStyle( + backgroundColor: + MaterialStateProperty.all(Colors.black), + padding: MaterialStateProperty.all( + const EdgeInsets.only(left: 30, right: 30)), + shape: MaterialStateProperty.all< + RoundedRectangleBorder>(RoundedRectangleBorder( + borderRadius: BorderRadius.circular(18.0), + ))), + child: const Text( + 'LEARN', + style: TextStyle(color: Colors.white), + )), + ); + }, + currentStep: _index, + onStepContinue: () { + Navigator.of(context) + .push(MaterialPageRoute( + builder: (context) => LessonSlideDeck( + lessonSlides: lessonsList[_index], + title: titles[_index]), + settings: const RouteSettings(name: "/lesson"))) + .then((_) => { + setState(() { + _listOfStates[_index] = StepState.complete; + UserPreferences.myUser.lessonProgress[_index] = 1; + // Update the database + UserPreferences.myUser.saveData(); + }) + }); + }, + onStepTapped: (int index) { + setState(() { + _index = index; + }); + }, + steps: stepBuilder(_listOfStates), + )), if (_hasReminder) // For any future implemenation in which we could build a reminder system AlertDialog( title: const Text('Lesson Reminder'), diff --git a/app/lib/screens/ProfileScreen.dart b/app/lib/screens/ProfileScreen.dart index ae4a2b7..996ead3 100644 --- a/app/lib/screens/ProfileScreen.dart +++ b/app/lib/screens/ProfileScreen.dart @@ -142,13 +142,14 @@ class _ProfileScreenState extends State { )), TextButton( onPressed: () { - Auth().signOut().then((value) => { - Navigator.pushReplacement( - context, - MaterialPageRoute( - builder: (BuildContext ctx) => - const LoginPage())) - }); + Auth().signOut().then((value) { + usermodel.UserPreferences.myUser.reset(); + Navigator.pushReplacement( + context, + MaterialPageRoute( + builder: (BuildContext ctx) => + const LoginPage())); + }); }, child: const Text( "Log Out",