Refactor ExerciseProvider and update LevelCard and DownResultWidget UI

This commit is contained in:
Naresh Pratista 2024-11-09 21:55:52 +07:00
parent 632d5de0c8
commit 3e16636963
3 changed files with 37 additions and 21 deletions

View File

@ -253,10 +253,16 @@ class ExerciseProvider extends ChangeNotifier {
return _answers[index].isNotEmpty;
}
void _resetReviewState() {
_reviewData = null;
_reviewExercises = [];
}
// API methods
Future<void> fetchExercises(String levelId) async {
_isLoading = true;
_currentExerciseIndex = 0;
_resetReviewState();
notifyListeners();
try {
@ -460,17 +466,31 @@ class ExerciseProvider extends ChangeNotifier {
void updateFrom(ExerciseProvider? previous) {
if (previous != null) {
_exercises = previous._exercises;
_matchingAnswers = previous._matchingAnswers;
_answers = previous._answers;
_leftColors = previous._leftColors;
_rightColors = previous._rightColors;
_currentExerciseIndex = previous._currentExerciseIndex;
_isLoading = previous._isLoading;
_nameTopic = previous._nameTopic;
_nameLevel = previous._nameLevel;
_studentLearningId = previous._studentLearningId;
_reviewData = previous._reviewData;
// Only copy non-review related state
if (!previous._reviewExercises.isNotEmpty) {
// If we're not coming from a review state
_exercises = previous._exercises;
_matchingAnswers = previous._matchingAnswers;
_answers = previous._answers;
_leftColors = previous._leftColors;
_rightColors = previous._rightColors;
_currentExerciseIndex = previous._currentExerciseIndex;
_nameTopic = previous._nameTopic;
_nameLevel = previous._nameLevel;
_studentLearningId = previous._studentLearningId;
} else {
// If we are coming from a review state, reset everything
_exercises = [];
_matchingAnswers = {};
_answers = [];
_leftColors = [];
_rightColors = [];
_currentExerciseIndex = 0;
_nameTopic = '';
_nameLevel = '';
_studentLearningId = previous._studentLearningId;
}
_isLoading = false;
}
}
}

View File

@ -42,7 +42,7 @@ class LevelCard extends StatelessWidget {
),
child: Stack(
children: [
if (isCompleted)
if (isAllowed && score > 0)
Positioned(
right: -23,
bottom: 4,
@ -122,18 +122,14 @@ class LevelCard extends StatelessWidget {
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 8.0),
child: CustomButton(
text: isCompleted
? 'Finished'
: (isAllowed ? 'Learn Now' : 'Locked'),
text: isAllowed ? 'Learn Now' : 'Locked',
textStyle:
isAllowed ? null : AppTextStyles.disableTextStyle,
width: double.infinity,
height: 36,
color: isCompleted
? Colors.green
: (isAllowed
? AppColors.yellowButtonColor
: AppColors.cardButtonColor),
color: isAllowed
? AppColors.yellowButtonColor
: AppColors.cardButtonColor,
onPressed: isAllowed
? () {
Navigator.push(

View File

@ -58,7 +58,7 @@ class DownResultWidget extends StatelessWidget {
),
const SizedBox(height: 8),
Text(
'Level $nextLevel',
'$nextLevel',
style: AppTextStyles.redTextStyle
.copyWith(fontSize: 20, fontWeight: FontWeight.w900),
),