fixing latestResponse

This commit is contained in:
William Jordan-Cooley 2024-06-25 15:24:58 -04:00
parent 2227c9d22d
commit a9ee9061b3
4 changed files with 17 additions and 3 deletions

View file

@ -18,6 +18,8 @@ class MultipleChoice {
int get correctAnswerIndex => choices.indexOf(answer);
int choiceIndex(String choice) => choices.indexOf(choice);
Color choiceColor(int index) =>
index == correctAnswerIndex ? AppConfig.success : AppConfig.warning;

View file

@ -40,12 +40,12 @@ class PracticeActivityRecordModel {
/// get the latest response index according to the response timeStamp
/// sort the responses by timestamp and get the index of the last response
int? get latestResponseIndex {
String? get latestResponse {
if (responses.isEmpty) {
return null;
}
responses.sort((a, b) => a.timestamp.compareTo(b.timestamp));
return responses.length - 1;
return responses[responses.length - 1].text;
}
void addResponse({

View file

@ -50,6 +50,7 @@ class MessagePracticeActivityCardState extends State<PracticeActivityCard> {
return langCode;
}
<<<<<<< Updated upstream
void loadInitialData() {
if (langCode == null) return;
updatePracticeActivity();
@ -75,6 +76,11 @@ class MessagePracticeActivityCardState extends State<PracticeActivityCard> {
else if (activities.isNotEmpty) {
practiceEvent = activities.last;
}
=======
practiceEvent =
widget.pangeaMessageEvent.practiceActivities(langCode).firstOrNull;
>>>>>>> Stashed changes
setState(() {});
}

View file

@ -63,7 +63,13 @@ class MessagePracticeActivityContentState
);
} else {
recordModel = recordEvent!.record;
selectedChoiceIndex = recordModel!.latestResponseIndex;
//Note that only MultipleChoice activities will have this so we probably should move this logic to the MultipleChoiceActivity widget
selectedChoiceIndex = recordModel?.latestResponse != null
? widget.practiceEvent.practiceActivity.multipleChoice
?.choiceIndex(recordModel!.latestResponse!)
: null;
recordSubmittedPreviousSession = true;
recordSubmittedThisSession = true;
}