Merge branch 'exercise-bug' into 'master'

Refactor ExerciseProvider and update LevelCard and DownResultWidget UI

See merge request profile-image/kedaireka/polinema-adapative-learning/mobile-adaptive-learning!10
This commit is contained in:
Naresh Pratista 2024-11-09 14:57:42 +00:00
commit cf967619e7
3 changed files with 37 additions and 21 deletions

View File

@ -253,10 +253,16 @@ class ExerciseProvider extends ChangeNotifier {
return _answers[index].isNotEmpty; return _answers[index].isNotEmpty;
} }
void _resetReviewState() {
_reviewData = null;
_reviewExercises = [];
}
// API methods // API methods
Future<void> fetchExercises(String levelId) async { Future<void> fetchExercises(String levelId) async {
_isLoading = true; _isLoading = true;
_currentExerciseIndex = 0; _currentExerciseIndex = 0;
_resetReviewState();
notifyListeners(); notifyListeners();
try { try {
@ -460,17 +466,31 @@ class ExerciseProvider extends ChangeNotifier {
void updateFrom(ExerciseProvider? previous) { void updateFrom(ExerciseProvider? previous) {
if (previous != null) { if (previous != null) {
// Only copy non-review related state
if (!previous._reviewExercises.isNotEmpty) {
// If we're not coming from a review state
_exercises = previous._exercises; _exercises = previous._exercises;
_matchingAnswers = previous._matchingAnswers; _matchingAnswers = previous._matchingAnswers;
_answers = previous._answers; _answers = previous._answers;
_leftColors = previous._leftColors; _leftColors = previous._leftColors;
_rightColors = previous._rightColors; _rightColors = previous._rightColors;
_currentExerciseIndex = previous._currentExerciseIndex; _currentExerciseIndex = previous._currentExerciseIndex;
_isLoading = previous._isLoading;
_nameTopic = previous._nameTopic; _nameTopic = previous._nameTopic;
_nameLevel = previous._nameLevel; _nameLevel = previous._nameLevel;
_studentLearningId = previous._studentLearningId; _studentLearningId = previous._studentLearningId;
_reviewData = previous._reviewData; } 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( child: Stack(
children: [ children: [
if (isCompleted) if (isAllowed && score > 0)
Positioned( Positioned(
right: -23, right: -23,
bottom: 4, bottom: 4,
@ -122,18 +122,14 @@ class LevelCard extends StatelessWidget {
child: Padding( child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 8.0), padding: const EdgeInsets.symmetric(horizontal: 8.0),
child: CustomButton( child: CustomButton(
text: isCompleted text: isAllowed ? 'Learn Now' : 'Locked',
? 'Finished'
: (isAllowed ? 'Learn Now' : 'Locked'),
textStyle: textStyle:
isAllowed ? null : AppTextStyles.disableTextStyle, isAllowed ? null : AppTextStyles.disableTextStyle,
width: double.infinity, width: double.infinity,
height: 36, height: 36,
color: isCompleted color: isAllowed
? Colors.green
: (isAllowed
? AppColors.yellowButtonColor ? AppColors.yellowButtonColor
: AppColors.cardButtonColor), : AppColors.cardButtonColor,
onPressed: isAllowed onPressed: isAllowed
? () { ? () {
Navigator.push( Navigator.push(

View File

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