Merge branch 'main' into analytics-target-languages
commit
51d684ac81
@ -0,0 +1,102 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:fluffychat/pangea/constants/pangea_event_types.dart';
|
||||
import 'package:fluffychat/pangea/enum/activity_type_enum.dart';
|
||||
import 'package:fluffychat/pangea/enum/construct_type_enum.dart';
|
||||
import 'package:fluffychat/pangea/extensions/pangea_room_extension/pangea_room_extension.dart';
|
||||
import 'package:fluffychat/pangea/matrix_event_wrappers/pangea_message_event.dart';
|
||||
import 'package:fluffychat/pangea/matrix_event_wrappers/practice_activity_event.dart';
|
||||
import 'package:fluffychat/pangea/models/practice_activities.dart/multiple_choice_activity_model.dart';
|
||||
import 'package:fluffychat/pangea/models/practice_activities.dart/practice_activity_model.dart';
|
||||
import 'package:matrix/matrix.dart';
|
||||
|
||||
/// Represents an item in the completion cache.
|
||||
class _RequestCacheItem {
|
||||
PracticeActivityRequest req;
|
||||
|
||||
Future<PracticeActivityEvent?> practiceActivityEvent;
|
||||
|
||||
_RequestCacheItem({
|
||||
required this.req,
|
||||
required this.practiceActivityEvent,
|
||||
});
|
||||
}
|
||||
|
||||
/// Controller for handling activity completions.
|
||||
class PracticeGenerationController {
|
||||
static final Map<int, _RequestCacheItem> _cache = {};
|
||||
Timer? _cacheClearTimer;
|
||||
|
||||
PracticeGenerationController() {
|
||||
_initializeCacheClearing();
|
||||
}
|
||||
|
||||
void _initializeCacheClearing() {
|
||||
const duration = Duration(minutes: 2);
|
||||
_cacheClearTimer = Timer.periodic(duration, (Timer t) => _clearCache());
|
||||
}
|
||||
|
||||
void _clearCache() {
|
||||
_cache.clear();
|
||||
}
|
||||
|
||||
void dispose() {
|
||||
_cacheClearTimer?.cancel();
|
||||
}
|
||||
|
||||
Future<PracticeActivityEvent?> _sendAndPackageEvent(
|
||||
PracticeActivityModel model,
|
||||
PangeaMessageEvent pangeaMessageEvent,
|
||||
) async {
|
||||
final Event? activityEvent = await pangeaMessageEvent.room.sendPangeaEvent(
|
||||
content: model.toJson(),
|
||||
parentEventId: pangeaMessageEvent.eventId,
|
||||
type: PangeaEventTypes.pangeaActivityRes,
|
||||
);
|
||||
|
||||
if (activityEvent == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return PracticeActivityEvent(
|
||||
event: activityEvent,
|
||||
timeline: pangeaMessageEvent.timeline,
|
||||
);
|
||||
}
|
||||
|
||||
Future<PracticeActivityEvent?> getPracticeActivity(
|
||||
PracticeActivityRequest req,
|
||||
PangeaMessageEvent event,
|
||||
) async {
|
||||
final int cacheKey = req.hashCode;
|
||||
|
||||
if (_cache.containsKey(cacheKey)) {
|
||||
return _cache[cacheKey]!.practiceActivityEvent;
|
||||
} else {
|
||||
//TODO - send request to server/bot, either via API or via event of type pangeaActivityReq
|
||||
// for now, just make and send the event from the client
|
||||
final Future<PracticeActivityEvent?> eventFuture =
|
||||
_sendAndPackageEvent(dummyModel(event), event);
|
||||
|
||||
_cache[cacheKey] =
|
||||
_RequestCacheItem(req: req, practiceActivityEvent: eventFuture);
|
||||
|
||||
return _cache[cacheKey]!.practiceActivityEvent;
|
||||
}
|
||||
}
|
||||
|
||||
PracticeActivityModel dummyModel(PangeaMessageEvent event) =>
|
||||
PracticeActivityModel(
|
||||
tgtConstructs: [
|
||||
ConstructIdentifier(lemma: "be", type: ConstructType.vocab),
|
||||
],
|
||||
activityType: ActivityTypeEnum.multipleChoice,
|
||||
langCode: event.messageDisplayLangCode,
|
||||
msgId: event.eventId,
|
||||
multipleChoice: MultipleChoice(
|
||||
question: "What is a synonym for 'happy'?",
|
||||
choices: ["sad", "angry", "joyful", "tired"],
|
||||
answer: "joyful",
|
||||
),
|
||||
);
|
||||
}
|
||||
@ -0,0 +1,94 @@
|
||||
import 'dart:async';
|
||||
import 'dart:developer';
|
||||
|
||||
import 'package:fluffychat/pangea/constants/pangea_event_types.dart';
|
||||
import 'package:fluffychat/pangea/controllers/pangea_controller.dart';
|
||||
import 'package:fluffychat/pangea/extensions/pangea_room_extension/pangea_room_extension.dart';
|
||||
import 'package:fluffychat/pangea/matrix_event_wrappers/practice_activity_event.dart';
|
||||
import 'package:fluffychat/pangea/models/practice_activities.dart/practice_activity_record_model.dart';
|
||||
import 'package:fluffychat/pangea/utils/error_handler.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:matrix/matrix.dart';
|
||||
|
||||
/// Represents an item in the completion cache.
|
||||
class _RecordCacheItem {
|
||||
PracticeActivityRecordModel data;
|
||||
|
||||
Future<Event?> recordEvent;
|
||||
|
||||
_RecordCacheItem({required this.data, required this.recordEvent});
|
||||
}
|
||||
|
||||
/// Controller for handling activity completions.
|
||||
class PracticeActivityRecordController {
|
||||
static final Map<int, _RecordCacheItem> _cache = {};
|
||||
late final PangeaController _pangeaController;
|
||||
Timer? _cacheClearTimer;
|
||||
|
||||
PracticeActivityRecordController(this._pangeaController) {
|
||||
_initializeCacheClearing();
|
||||
}
|
||||
|
||||
void _initializeCacheClearing() {
|
||||
const duration = Duration(minutes: 2);
|
||||
_cacheClearTimer = Timer.periodic(duration, (Timer t) => _clearCache());
|
||||
}
|
||||
|
||||
void _clearCache() {
|
||||
_cache.clear();
|
||||
}
|
||||
|
||||
void dispose() {
|
||||
_cacheClearTimer?.cancel();
|
||||
}
|
||||
|
||||
/// Sends a practice activity record to the server and returns the corresponding event.
|
||||
///
|
||||
/// The [recordModel] parameter is the model representing the practice activity record.
|
||||
/// The [practiceActivityEvent] parameter is the event associated with the practice activity.
|
||||
/// Note that the system will send a new event if the model has changed in any way ie it is
|
||||
/// a new completion of the practice activity. However, it will cache previous sends to ensure
|
||||
/// that opening and closing of the widget does not result in multiple sends of the same data.
|
||||
/// It allows checks the data to make sure that it contains responses to the practice activity
|
||||
/// and does not represent a blank record with no actual completion to be saved.
|
||||
///
|
||||
/// Returns a [Future] that completes with the corresponding [Event] object.
|
||||
Future<Event?> send(
|
||||
PracticeActivityRecordModel recordModel,
|
||||
PracticeActivityEvent practiceActivityEvent,
|
||||
) async {
|
||||
final int cacheKey = recordModel.hashCode;
|
||||
|
||||
if (recordModel.responses.isEmpty) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (_cache.containsKey(cacheKey)) {
|
||||
return _cache[cacheKey]!.recordEvent;
|
||||
} else {
|
||||
final Future<Event?> eventFuture = practiceActivityEvent.event.room
|
||||
.sendPangeaEvent(
|
||||
content: recordModel.toJson(),
|
||||
parentEventId: practiceActivityEvent.event.eventId,
|
||||
type: PangeaEventTypes.activityRecord,
|
||||
)
|
||||
.catchError((e) {
|
||||
debugger(when: kDebugMode);
|
||||
ErrorHandler.logError(
|
||||
e: e,
|
||||
s: StackTrace.current,
|
||||
data: {
|
||||
'recordModel': recordModel.toJson(),
|
||||
'practiceActivityEvent': practiceActivityEvent.event.toJson(),
|
||||
},
|
||||
);
|
||||
return null;
|
||||
});
|
||||
|
||||
_cache[cacheKey] =
|
||||
_RecordCacheItem(data: recordModel, recordEvent: eventFuture);
|
||||
|
||||
return _cache[cacheKey]!.recordEvent;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,16 @@
|
||||
enum ActivityTypeEnum { multipleChoice, freeResponse, listening, speaking }
|
||||
|
||||
extension ActivityTypeExtension on ActivityTypeEnum {
|
||||
String get string {
|
||||
switch (this) {
|
||||
case ActivityTypeEnum.multipleChoice:
|
||||
return 'multiple_choice';
|
||||
case ActivityTypeEnum.freeResponse:
|
||||
return 'free_response';
|
||||
case ActivityTypeEnum.listening:
|
||||
return 'listening';
|
||||
case ActivityTypeEnum.speaking:
|
||||
return 'speaking';
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,43 @@
|
||||
// assistance state is, user has not typed a message, user has typed a message and IGC has not run,
|
||||
// IGC is running, IGC has run and there are remaining steps (either IT or IGC), or all steps are done
|
||||
import 'package:fluffychat/config/app_config.dart';
|
||||
import 'package:fluffychat/pangea/constants/colors.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
||||
|
||||
enum AssistanceState {
|
||||
noMessage,
|
||||
notFetched,
|
||||
fetching,
|
||||
fetched,
|
||||
complete,
|
||||
}
|
||||
|
||||
extension AssistanceStateExtension on AssistanceState {
|
||||
Color stateColor(context) {
|
||||
switch (this) {
|
||||
case AssistanceState.noMessage:
|
||||
case AssistanceState.notFetched:
|
||||
case AssistanceState.fetching:
|
||||
return Theme.of(context).colorScheme.primary;
|
||||
case AssistanceState.fetched:
|
||||
return PangeaColors.igcError;
|
||||
case AssistanceState.complete:
|
||||
return AppConfig.success;
|
||||
}
|
||||
}
|
||||
|
||||
String tooltip(L10n l10n) {
|
||||
switch (this) {
|
||||
case AssistanceState.noMessage:
|
||||
case AssistanceState.notFetched:
|
||||
return l10n.runGrammarCorrection;
|
||||
case AssistanceState.fetching:
|
||||
return "";
|
||||
case AssistanceState.fetched:
|
||||
return l10n.grammarCorrectionFailed;
|
||||
case AssistanceState.complete:
|
||||
return l10n.grammarCorrectionComplete;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,9 +0,0 @@
|
||||
// relates to a pangea representation event
|
||||
// the matrix even fits the form of a regular matrix audio event
|
||||
// but with something to distinguish it as a pangea audio event
|
||||
|
||||
import 'package:matrix/matrix.dart';
|
||||
|
||||
class PangeaAudioEvent {
|
||||
Event? _event;
|
||||
}
|
||||
@ -0,0 +1,24 @@
|
||||
import 'package:fluffychat/pangea/extensions/pangea_event_extension.dart';
|
||||
import 'package:fluffychat/pangea/models/practice_activities.dart/practice_activity_record_model.dart';
|
||||
import 'package:matrix/matrix.dart';
|
||||
|
||||
import '../constants/pangea_event_types.dart';
|
||||
|
||||
class PracticeActivityRecordEvent {
|
||||
Event event;
|
||||
|
||||
PracticeActivityRecordModel? _content;
|
||||
|
||||
PracticeActivityRecordEvent({required this.event}) {
|
||||
if (event.type != PangeaEventTypes.activityRecord) {
|
||||
throw Exception(
|
||||
"${event.type} should not be used to make a PracticeActivityRecordEvent",
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
PracticeActivityRecordModel? get record {
|
||||
_content ??= event.getPangeaContent<PracticeActivityRecordModel>();
|
||||
return _content!;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,67 @@
|
||||
import 'dart:developer';
|
||||
|
||||
import 'package:fluffychat/pangea/extensions/pangea_event_extension.dart';
|
||||
import 'package:fluffychat/pangea/matrix_event_wrappers/practice_acitivity_record_event.dart';
|
||||
import 'package:fluffychat/pangea/models/practice_activities.dart/practice_activity_model.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:matrix/matrix.dart';
|
||||
|
||||
import '../constants/pangea_event_types.dart';
|
||||
|
||||
class PracticeActivityEvent {
|
||||
Event event;
|
||||
Timeline? timeline;
|
||||
PracticeActivityModel? _content;
|
||||
|
||||
PracticeActivityEvent({
|
||||
required this.event,
|
||||
required this.timeline,
|
||||
content,
|
||||
}) {
|
||||
if (content != null) {
|
||||
if (!kDebugMode) {
|
||||
throw Exception(
|
||||
"content should not be set on product, just a dev placeholder",
|
||||
);
|
||||
} else {
|
||||
_content = content;
|
||||
}
|
||||
}
|
||||
if (event.type != PangeaEventTypes.pangeaActivityRes) {
|
||||
throw Exception(
|
||||
"${event.type} should not be used to make a PracticeActivityEvent",
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
PracticeActivityModel get practiceActivity {
|
||||
_content ??= event.getPangeaContent<PracticeActivityModel>();
|
||||
return _content!;
|
||||
}
|
||||
|
||||
//in aggregatedEvents for the event, find all practiceActivityRecordEvents whose sender matches the client's userId
|
||||
List<PracticeActivityRecordEvent> get allRecords {
|
||||
if (timeline == null) {
|
||||
debugger(when: kDebugMode);
|
||||
return [];
|
||||
}
|
||||
final List<Event> records = event
|
||||
.aggregatedEvents(timeline!, PangeaEventTypes.activityRecord)
|
||||
.toList();
|
||||
|
||||
return records
|
||||
.map((event) => PracticeActivityRecordEvent(event: event))
|
||||
.toList();
|
||||
}
|
||||
|
||||
List<PracticeActivityRecordEvent> get userRecords => allRecords
|
||||
.where(
|
||||
(recordEvent) =>
|
||||
recordEvent.event.senderId == recordEvent.event.room.client.userID,
|
||||
)
|
||||
.toList();
|
||||
|
||||
/// Checks if there are any user records in the list for this activity,
|
||||
/// and, if so, then the activity is complete
|
||||
bool get isComplete => userRecords.isNotEmpty;
|
||||
}
|
||||
@ -0,0 +1,41 @@
|
||||
import 'package:fluffychat/config/app_config.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class MultipleChoice {
|
||||
final String question;
|
||||
final List<String> choices;
|
||||
final String answer;
|
||||
|
||||
MultipleChoice({
|
||||
required this.question,
|
||||
required this.choices,
|
||||
required this.answer,
|
||||
});
|
||||
|
||||
bool isCorrect(int index) => index == correctAnswerIndex;
|
||||
|
||||
bool get isValidQuestion => choices.contains(answer);
|
||||
|
||||
int get correctAnswerIndex => choices.indexOf(answer);
|
||||
|
||||
int choiceIndex(String choice) => choices.indexOf(choice);
|
||||
|
||||
Color choiceColor(int index) =>
|
||||
index == correctAnswerIndex ? AppConfig.success : AppConfig.warning;
|
||||
|
||||
factory MultipleChoice.fromJson(Map<String, dynamic> json) {
|
||||
return MultipleChoice(
|
||||
question: json['question'] as String,
|
||||
choices: (json['choices'] as List).map((e) => e as String).toList(),
|
||||
answer: json['answer'] as String,
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
return {
|
||||
'question': question,
|
||||
'choices': choices,
|
||||
'answer': answer,
|
||||
};
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,280 @@
|
||||
import 'dart:developer';
|
||||
|
||||
import 'package:fluffychat/pangea/enum/activity_type_enum.dart';
|
||||
import 'package:fluffychat/pangea/enum/construct_type_enum.dart';
|
||||
import 'package:fluffychat/pangea/models/practice_activities.dart/multiple_choice_activity_model.dart';
|
||||
import 'package:fluffychat/pangea/utils/error_handler.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
|
||||
class ConstructIdentifier {
|
||||
final String lemma;
|
||||
final ConstructType type;
|
||||
|
||||
ConstructIdentifier({required this.lemma, required this.type});
|
||||
|
||||
factory ConstructIdentifier.fromJson(Map<String, dynamic> json) {
|
||||
try {
|
||||
return ConstructIdentifier(
|
||||
lemma: json['lemma'] as String,
|
||||
type: ConstructType.values.firstWhere(
|
||||
(e) => e.string == json['type'],
|
||||
),
|
||||
);
|
||||
} catch (e, s) {
|
||||
debugger(when: kDebugMode);
|
||||
ErrorHandler.logError(e: e, s: s, data: json);
|
||||
rethrow;
|
||||
}
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
return {
|
||||
'lemma': lemma,
|
||||
'type': type.string,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
class CandidateMessage {
|
||||
final String msgId;
|
||||
final String roomId;
|
||||
final String text;
|
||||
|
||||
CandidateMessage({
|
||||
required this.msgId,
|
||||
required this.roomId,
|
||||
required this.text,
|
||||
});
|
||||
|
||||
factory CandidateMessage.fromJson(Map<String, dynamic> json) {
|
||||
return CandidateMessage(
|
||||
msgId: json['msg_id'] as String,
|
||||
roomId: json['room_id'] as String,
|
||||
text: json['text'] as String,
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
return {
|
||||
'msg_id': msgId,
|
||||
'room_id': roomId,
|
||||
'text': text,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
enum PracticeActivityMode { focus, srs }
|
||||
|
||||
extension on PracticeActivityMode {
|
||||
String get value {
|
||||
switch (this) {
|
||||
case PracticeActivityMode.focus:
|
||||
return 'focus';
|
||||
case PracticeActivityMode.srs:
|
||||
return 'srs';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class PracticeActivityRequest {
|
||||
final PracticeActivityMode? mode;
|
||||
final List<ConstructIdentifier>? targetConstructs;
|
||||
final List<CandidateMessage>? candidateMessages;
|
||||
final List<String>? userIds;
|
||||
final ActivityTypeEnum? activityType;
|
||||
final int? numActivities;
|
||||
|
||||
PracticeActivityRequest({
|
||||
this.mode,
|
||||
this.targetConstructs,
|
||||
this.candidateMessages,
|
||||
this.userIds,
|
||||
this.activityType,
|
||||
this.numActivities,
|
||||
});
|
||||
|
||||
factory PracticeActivityRequest.fromJson(Map<String, dynamic> json) {
|
||||
return PracticeActivityRequest(
|
||||
mode: PracticeActivityMode.values.firstWhere(
|
||||
(e) => e.value == json['mode'],
|
||||
),
|
||||
targetConstructs: (json['target_constructs'] as List?)
|
||||
?.map((e) => ConstructIdentifier.fromJson(e as Map<String, dynamic>))
|
||||
.toList(),
|
||||
candidateMessages: (json['candidate_msgs'] as List)
|
||||
.map((e) => CandidateMessage.fromJson(e as Map<String, dynamic>))
|
||||
.toList(),
|
||||
userIds: (json['user_ids'] as List?)?.map((e) => e as String).toList(),
|
||||
activityType: ActivityTypeEnum.values.firstWhere(
|
||||
(e) => e.toString().split('.').last == json['activity_type'],
|
||||
),
|
||||
numActivities: json['num_activities'] as int,
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
return {
|
||||
'mode': mode?.value,
|
||||
'target_constructs': targetConstructs?.map((e) => e.toJson()).toList(),
|
||||
'candidate_msgs': candidateMessages?.map((e) => e.toJson()).toList(),
|
||||
'user_ids': userIds,
|
||||
'activity_type': activityType?.toString().split('.').last,
|
||||
'num_activities': numActivities,
|
||||
};
|
||||
}
|
||||
|
||||
// override operator == and hashCode
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
if (identical(this, other)) return true;
|
||||
|
||||
return other is PracticeActivityRequest &&
|
||||
other.mode == mode &&
|
||||
other.targetConstructs == targetConstructs &&
|
||||
other.candidateMessages == candidateMessages &&
|
||||
other.userIds == userIds &&
|
||||
other.activityType == activityType &&
|
||||
other.numActivities == numActivities;
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode {
|
||||
return mode.hashCode ^
|
||||
targetConstructs.hashCode ^
|
||||
candidateMessages.hashCode ^
|
||||
userIds.hashCode ^
|
||||
activityType.hashCode ^
|
||||
numActivities.hashCode;
|
||||
}
|
||||
}
|
||||
|
||||
class FreeResponse {
|
||||
final String question;
|
||||
final String correctAnswer;
|
||||
final String gradingGuide;
|
||||
|
||||
FreeResponse({
|
||||
required this.question,
|
||||
required this.correctAnswer,
|
||||
required this.gradingGuide,
|
||||
});
|
||||
|
||||
factory FreeResponse.fromJson(Map<String, dynamic> json) {
|
||||
return FreeResponse(
|
||||
question: json['question'] as String,
|
||||
correctAnswer: json['correct_answer'] as String,
|
||||
gradingGuide: json['grading_guide'] as String,
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
return {
|
||||
'question': question,
|
||||
'correct_answer': correctAnswer,
|
||||
'grading_guide': gradingGuide,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
class Listening {
|
||||
final String audioUrl;
|
||||
final String text;
|
||||
|
||||
Listening({required this.audioUrl, required this.text});
|
||||
|
||||
factory Listening.fromJson(Map<String, dynamic> json) {
|
||||
return Listening(
|
||||
audioUrl: json['audio_url'] as String,
|
||||
text: json['text'] as String,
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
return {
|
||||
'audio_url': audioUrl,
|
||||
'text': text,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
class Speaking {
|
||||
final String text;
|
||||
|
||||
Speaking({required this.text});
|
||||
|
||||
factory Speaking.fromJson(Map<String, dynamic> json) {
|
||||
return Speaking(
|
||||
text: json['text'] as String,
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
return {
|
||||
'text': text,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
class PracticeActivityModel {
|
||||
final List<ConstructIdentifier> tgtConstructs;
|
||||
final String langCode;
|
||||
final String msgId;
|
||||
final ActivityTypeEnum activityType;
|
||||
final MultipleChoice? multipleChoice;
|
||||
final Listening? listening;
|
||||
final Speaking? speaking;
|
||||
final FreeResponse? freeResponse;
|
||||
|
||||
PracticeActivityModel({
|
||||
required this.tgtConstructs,
|
||||
required this.langCode,
|
||||
required this.msgId,
|
||||
required this.activityType,
|
||||
this.multipleChoice,
|
||||
this.listening,
|
||||
this.speaking,
|
||||
this.freeResponse,
|
||||
});
|
||||
|
||||
factory PracticeActivityModel.fromJson(Map<String, dynamic> json) {
|
||||
return PracticeActivityModel(
|
||||
tgtConstructs: (json['tgt_constructs'] as List)
|
||||
.map((e) => ConstructIdentifier.fromJson(e as Map<String, dynamic>))
|
||||
.toList(),
|
||||
langCode: json['lang_code'] as String,
|
||||
msgId: json['msg_id'] as String,
|
||||
activityType: ActivityTypeEnum.values.firstWhere(
|
||||
(e) => e.string == json['activity_type'],
|
||||
),
|
||||
multipleChoice: json['multiple_choice'] != null
|
||||
? MultipleChoice.fromJson(
|
||||
json['multiple_choice'] as Map<String, dynamic>,
|
||||
)
|
||||
: null,
|
||||
listening: json['listening'] != null
|
||||
? Listening.fromJson(json['listening'] as Map<String, dynamic>)
|
||||
: null,
|
||||
speaking: json['speaking'] != null
|
||||
? Speaking.fromJson(json['speaking'] as Map<String, dynamic>)
|
||||
: null,
|
||||
freeResponse: json['free_response'] != null
|
||||
? FreeResponse.fromJson(
|
||||
json['free_response'] as Map<String, dynamic>,
|
||||
)
|
||||
: null,
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
return {
|
||||
'tgt_constructs': tgtConstructs.map((e) => e.toJson()).toList(),
|
||||
'lang_code': langCode,
|
||||
'msg_id': msgId,
|
||||
'activity_type': activityType.toString().split('.').last,
|
||||
'multiple_choice': multipleChoice?.toJson(),
|
||||
'listening': listening?.toJson(),
|
||||
'speaking': speaking?.toJson(),
|
||||
'free_response': freeResponse?.toJson(),
|
||||
};
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,137 @@
|
||||
// record the options that the user selected
|
||||
// note that this is not the same as the correct answer
|
||||
// the user might have selected multiple options before
|
||||
// finding the answer
|
||||
import 'dart:developer';
|
||||
import 'dart:typed_data';
|
||||
|
||||
class PracticeActivityRecordModel {
|
||||
final String? question;
|
||||
late List<ActivityResponse> responses;
|
||||
|
||||
PracticeActivityRecordModel({
|
||||
required this.question,
|
||||
List<ActivityResponse>? responses,
|
||||
}) {
|
||||
if (responses == null) {
|
||||
this.responses = List<ActivityResponse>.empty(growable: true);
|
||||
} else {
|
||||
this.responses = responses;
|
||||
}
|
||||
}
|
||||
|
||||
factory PracticeActivityRecordModel.fromJson(
|
||||
Map<String, dynamic> json,
|
||||
) {
|
||||
return PracticeActivityRecordModel(
|
||||
question: json['question'] as String,
|
||||
responses: (json['responses'] as List)
|
||||
.map((e) => ActivityResponse.fromJson(e as Map<String, dynamic>))
|
||||
.toList(),
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
return {
|
||||
'question': question,
|
||||
'responses': responses.map((e) => e.toJson()).toList(),
|
||||
};
|
||||
}
|
||||
|
||||
/// get the latest response index according to the response timeStamp
|
||||
/// sort the responses by timestamp and get the index of the last response
|
||||
String? get latestResponse {
|
||||
if (responses.isEmpty) {
|
||||
return null;
|
||||
}
|
||||
responses.sort((a, b) => a.timestamp.compareTo(b.timestamp));
|
||||
return responses[responses.length - 1].text;
|
||||
}
|
||||
|
||||
void addResponse({
|
||||
String? text,
|
||||
Uint8List? audioBytes,
|
||||
Uint8List? imageBytes,
|
||||
}) {
|
||||
try {
|
||||
responses.add(
|
||||
ActivityResponse(
|
||||
text: text,
|
||||
audioBytes: audioBytes,
|
||||
imageBytes: imageBytes,
|
||||
timestamp: DateTime.now(),
|
||||
),
|
||||
);
|
||||
} catch (e) {
|
||||
debugger();
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
if (identical(this, other)) return true;
|
||||
|
||||
return other is PracticeActivityRecordModel &&
|
||||
other.question == question &&
|
||||
other.responses.length == responses.length &&
|
||||
List.generate(
|
||||
responses.length,
|
||||
(index) => responses[index] == other.responses[index],
|
||||
).every((element) => element);
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode => question.hashCode ^ responses.hashCode;
|
||||
}
|
||||
|
||||
class ActivityResponse {
|
||||
// the user's response
|
||||
// has nullable string, nullable audio bytes, nullable image bytes, and timestamp
|
||||
final String? text;
|
||||
final Uint8List? audioBytes;
|
||||
final Uint8List? imageBytes;
|
||||
final DateTime timestamp;
|
||||
|
||||
ActivityResponse({
|
||||
this.text,
|
||||
this.audioBytes,
|
||||
this.imageBytes,
|
||||
required this.timestamp,
|
||||
});
|
||||
|
||||
factory ActivityResponse.fromJson(Map<String, dynamic> json) {
|
||||
return ActivityResponse(
|
||||
text: json['text'] as String?,
|
||||
audioBytes: json['audio'] as Uint8List?,
|
||||
imageBytes: json['image'] as Uint8List?,
|
||||
timestamp: DateTime.parse(json['timestamp'] as String),
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
return {
|
||||
'text': text,
|
||||
'audio': audioBytes,
|
||||
'image': imageBytes,
|
||||
'timestamp': timestamp.toIso8601String(),
|
||||
};
|
||||
}
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
if (identical(this, other)) return true;
|
||||
|
||||
return other is ActivityResponse &&
|
||||
other.text == text &&
|
||||
other.audioBytes == audioBytes &&
|
||||
other.imageBytes == imageBytes &&
|
||||
other.timestamp == timestamp;
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode =>
|
||||
text.hashCode ^
|
||||
audioBytes.hashCode ^
|
||||
imageBytes.hashCode ^
|
||||
timestamp.hashCode;
|
||||
}
|
||||
@ -0,0 +1,96 @@
|
||||
import 'package:fluffychat/pangea/enum/message_mode_enum.dart';
|
||||
import 'package:fluffychat/pangea/widgets/chat/message_toolbar.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class MessageButtons extends StatelessWidget {
|
||||
final ToolbarDisplayController? toolbarController;
|
||||
|
||||
const MessageButtons({
|
||||
super.key,
|
||||
this.toolbarController,
|
||||
});
|
||||
|
||||
void showActivity(BuildContext context) {
|
||||
toolbarController?.showToolbar(
|
||||
context,
|
||||
mode: MessageMode.practiceActivity,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
if (toolbarController == null) {
|
||||
return const SizedBox.shrink();
|
||||
}
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(right: 8.0),
|
||||
child: Row(
|
||||
children: [
|
||||
HoverIconButton(
|
||||
icon: MessageMode.practiceActivity.icon,
|
||||
onTap: () => showActivity(context),
|
||||
primaryColor: Theme.of(context).colorScheme.primary,
|
||||
tooltip: MessageMode.practiceActivity.tooltip(context),
|
||||
),
|
||||
|
||||
// Additional buttons can be added here in the future
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class HoverIconButton extends StatefulWidget {
|
||||
final IconData icon;
|
||||
final VoidCallback onTap;
|
||||
final Color primaryColor;
|
||||
final String tooltip;
|
||||
|
||||
const HoverIconButton({
|
||||
super.key,
|
||||
required this.icon,
|
||||
required this.onTap,
|
||||
required this.primaryColor,
|
||||
required this.tooltip,
|
||||
});
|
||||
|
||||
@override
|
||||
_HoverIconButtonState createState() => _HoverIconButtonState();
|
||||
}
|
||||
|
||||
class _HoverIconButtonState extends State<HoverIconButton> {
|
||||
bool _isHovered = false;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Tooltip(
|
||||
message: widget.tooltip,
|
||||
child: InkWell(
|
||||
onTap: widget.onTap,
|
||||
onHover: (hovering) {
|
||||
setState(() => _isHovered = hovering);
|
||||
},
|
||||
borderRadius: BorderRadius.circular(100),
|
||||
child: Container(
|
||||
decoration: BoxDecoration(
|
||||
color: _isHovered ? widget.primaryColor : null,
|
||||
borderRadius: BorderRadius.circular(100),
|
||||
border: Border.all(
|
||||
width: 1,
|
||||
color: widget.primaryColor,
|
||||
),
|
||||
),
|
||||
padding: const EdgeInsets.all(2),
|
||||
child: Icon(
|
||||
widget.icon,
|
||||
size: 18,
|
||||
// when hovered, use themeData to get background color, otherwise use primary
|
||||
color: _isHovered
|
||||
? Theme.of(context).scaffoldBackgroundColor
|
||||
: widget.primaryColor,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,61 @@
|
||||
import 'package:fluffychat/pangea/matrix_event_wrappers/pangea_message_event.dart';
|
||||
import 'package:fluffychat/pangea/matrix_event_wrappers/practice_activity_event.dart';
|
||||
import 'package:fluffychat/pangea/models/practice_activities.dart/practice_activity_model.dart';
|
||||
import 'package:fluffychat/widgets/matrix.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
||||
|
||||
class GeneratePracticeActivityButton extends StatelessWidget {
|
||||
final PangeaMessageEvent pangeaMessageEvent;
|
||||
final Function(PracticeActivityEvent?) onActivityGenerated;
|
||||
|
||||
const GeneratePracticeActivityButton({
|
||||
super.key,
|
||||
required this.pangeaMessageEvent,
|
||||
required this.onActivityGenerated,
|
||||
});
|
||||
|
||||
//TODO - probably disable the generation of activities for specific messages
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return ElevatedButton(
|
||||
onPressed: () async {
|
||||
final String? l2Code = MatrixState.pangeaController.languageController
|
||||
.activeL1Model()
|
||||
?.langCode;
|
||||
|
||||
if (l2Code == null) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(L10n.of(context)!.noLanguagesSet),
|
||||
),
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
final PracticeActivityEvent? practiceActivityEvent = await MatrixState
|
||||
.pangeaController.practiceGenerationController
|
||||
.getPracticeActivity(
|
||||
PracticeActivityRequest(
|
||||
candidateMessages: [
|
||||
CandidateMessage(
|
||||
msgId: pangeaMessageEvent.eventId,
|
||||
roomId: pangeaMessageEvent.room.id,
|
||||
text:
|
||||
pangeaMessageEvent.representationByLanguage(l2Code)?.text ??
|
||||
pangeaMessageEvent.body,
|
||||
),
|
||||
],
|
||||
userIds: pangeaMessageEvent.room.client.userID != null
|
||||
? [pangeaMessageEvent.room.client.userID!]
|
||||
: null,
|
||||
),
|
||||
pangeaMessageEvent,
|
||||
);
|
||||
|
||||
onActivityGenerated(practiceActivityEvent);
|
||||
},
|
||||
child: Text(L10n.of(context)!.practice),
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,69 @@
|
||||
import 'package:collection/collection.dart';
|
||||
import 'package:fluffychat/pangea/choreographer/widgets/choice_array.dart';
|
||||
import 'package:fluffychat/pangea/matrix_event_wrappers/practice_activity_event.dart';
|
||||
import 'package:fluffychat/pangea/models/practice_activities.dart/practice_activity_model.dart';
|
||||
import 'package:fluffychat/pangea/widgets/practice_activity/practice_activity_content.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class MultipleChoiceActivity extends StatelessWidget {
|
||||
final MessagePracticeActivityContentState card;
|
||||
final Function(int) updateChoice;
|
||||
final bool isActive;
|
||||
|
||||
const MultipleChoiceActivity({
|
||||
super.key,
|
||||
required this.card,
|
||||
required this.updateChoice,
|
||||
required this.isActive,
|
||||
});
|
||||
|
||||
PracticeActivityEvent get practiceEvent => card.practiceEvent;
|
||||
|
||||
int? get selectedChoiceIndex => card.selectedChoiceIndex;
|
||||
|
||||
bool get submitted => card.recordSubmittedThisSession;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final PracticeActivityModel practiceActivity =
|
||||
practiceEvent.practiceActivity;
|
||||
|
||||
return Container(
|
||||
padding: const EdgeInsets.all(8),
|
||||
child: Column(
|
||||
children: [
|
||||
Text(
|
||||
practiceActivity.multipleChoice!.question,
|
||||
style: const TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
ChoicesArray(
|
||||
isLoading: false,
|
||||
uniqueKeyForLayerLink: (index) => "multiple_choice_$index",
|
||||
originalSpan: "placeholder",
|
||||
onPressed: updateChoice,
|
||||
selectedChoiceIndex: selectedChoiceIndex,
|
||||
choices: practiceActivity.multipleChoice!.choices
|
||||
.mapIndexed(
|
||||
(index, value) => Choice(
|
||||
text: value,
|
||||
color: (selectedChoiceIndex == index ||
|
||||
practiceActivity.multipleChoice!
|
||||
.isCorrect(index)) &&
|
||||
submitted
|
||||
? practiceActivity.multipleChoice!.choiceColor(index)
|
||||
: null,
|
||||
isGold: practiceActivity.multipleChoice!.isCorrect(index),
|
||||
),
|
||||
)
|
||||
.toList(),
|
||||
isActive: isActive,
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,108 @@
|
||||
import 'dart:developer';
|
||||
|
||||
import 'package:fluffychat/pangea/enum/message_mode_enum.dart';
|
||||
import 'package:fluffychat/pangea/matrix_event_wrappers/pangea_message_event.dart';
|
||||
import 'package:fluffychat/pangea/matrix_event_wrappers/practice_activity_event.dart';
|
||||
import 'package:fluffychat/pangea/utils/bot_style.dart';
|
||||
import 'package:fluffychat/pangea/widgets/chat/message_toolbar.dart';
|
||||
import 'package:fluffychat/pangea/widgets/practice_activity/practice_activity_content.dart';
|
||||
import 'package:fluffychat/widgets/matrix.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
||||
|
||||
class PracticeActivityCard extends StatefulWidget {
|
||||
final PangeaMessageEvent pangeaMessageEvent;
|
||||
final MessageToolbarState controller;
|
||||
|
||||
const PracticeActivityCard({
|
||||
super.key,
|
||||
required this.pangeaMessageEvent,
|
||||
required this.controller,
|
||||
});
|
||||
|
||||
@override
|
||||
MessagePracticeActivityCardState createState() =>
|
||||
MessagePracticeActivityCardState();
|
||||
}
|
||||
|
||||
class MessagePracticeActivityCardState extends State<PracticeActivityCard> {
|
||||
PracticeActivityEvent? practiceEvent;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
loadInitialData();
|
||||
}
|
||||
|
||||
String? get langCode {
|
||||
final String? langCode = MatrixState.pangeaController.languageController
|
||||
.activeL2Model()
|
||||
?.langCode;
|
||||
|
||||
if (langCode == null) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(content: Text(L10n.of(context)!.noLanguagesSet)),
|
||||
);
|
||||
debugger(when: kDebugMode);
|
||||
return null;
|
||||
}
|
||||
return langCode;
|
||||
}
|
||||
|
||||
void loadInitialData() {
|
||||
if (langCode == null) return;
|
||||
updatePracticeActivity();
|
||||
if (practiceEvent == null) {
|
||||
debugger(when: kDebugMode);
|
||||
}
|
||||
}
|
||||
|
||||
void updatePracticeActivity() {
|
||||
if (langCode == null) return;
|
||||
final List<PracticeActivityEvent> activities =
|
||||
widget.pangeaMessageEvent.practiceActivities(langCode!);
|
||||
if (activities.isEmpty) return;
|
||||
final List<PracticeActivityEvent> incompleteActivities =
|
||||
activities.where((element) => !element.isComplete).toList();
|
||||
debugPrint("total events: ${activities.length}");
|
||||
debugPrint("incomplete practice events: ${incompleteActivities.length}");
|
||||
|
||||
// TODO update to show next activity
|
||||
practiceEvent = activities.first;
|
||||
// // if an incomplete activity is found, show that
|
||||
// if (incompleteActivities.isNotEmpty) {
|
||||
// practiceEvent = incompleteActivities.first;
|
||||
// }
|
||||
// // if no incomplete activity is found, show the last activity
|
||||
// else if (activities.isNotEmpty) {
|
||||
// practiceEvent = activities.last;
|
||||
// }
|
||||
setState(() {});
|
||||
}
|
||||
|
||||
void showNextActivity() {
|
||||
if (langCode == null) return;
|
||||
updatePracticeActivity();
|
||||
widget.controller.updateMode(MessageMode.practiceActivity);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
if (practiceEvent == null) {
|
||||
return Text(
|
||||
L10n.of(context)!.noActivitiesFound,
|
||||
style: BotStyle.text(context),
|
||||
);
|
||||
// return GeneratePracticeActivityButton(
|
||||
// pangeaMessageEvent: widget.pangeaMessageEvent,
|
||||
// onActivityGenerated: updatePracticeActivity,
|
||||
// );
|
||||
}
|
||||
return PracticeActivityContent(
|
||||
practiceEvent: practiceEvent!,
|
||||
pangeaMessageEvent: widget.pangeaMessageEvent,
|
||||
controller: this,
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,165 @@
|
||||
import 'package:collection/collection.dart';
|
||||
import 'package:fluffychat/config/app_config.dart';
|
||||
import 'package:fluffychat/pangea/enum/activity_type_enum.dart';
|
||||
import 'package:fluffychat/pangea/matrix_event_wrappers/pangea_message_event.dart';
|
||||
import 'package:fluffychat/pangea/matrix_event_wrappers/practice_acitivity_record_event.dart';
|
||||
import 'package:fluffychat/pangea/matrix_event_wrappers/practice_activity_event.dart';
|
||||
import 'package:fluffychat/pangea/models/practice_activities.dart/practice_activity_record_model.dart';
|
||||
import 'package:fluffychat/pangea/utils/error_handler.dart';
|
||||
import 'package:fluffychat/pangea/widgets/practice_activity/multiple_choice_activity.dart';
|
||||
import 'package:fluffychat/pangea/widgets/practice_activity/practice_activity_card.dart';
|
||||
import 'package:fluffychat/widgets/matrix.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
||||
|
||||
class PracticeActivityContent extends StatefulWidget {
|
||||
final PracticeActivityEvent practiceEvent;
|
||||
final PangeaMessageEvent pangeaMessageEvent;
|
||||
final MessagePracticeActivityCardState controller;
|
||||
|
||||
const PracticeActivityContent({
|
||||
super.key,
|
||||
required this.practiceEvent,
|
||||
required this.pangeaMessageEvent,
|
||||
required this.controller,
|
||||
});
|
||||
|
||||
@override
|
||||
MessagePracticeActivityContentState createState() =>
|
||||
MessagePracticeActivityContentState();
|
||||
}
|
||||
|
||||
class MessagePracticeActivityContentState
|
||||
extends State<PracticeActivityContent> {
|
||||
int? selectedChoiceIndex;
|
||||
PracticeActivityRecordModel? recordModel;
|
||||
bool recordSubmittedThisSession = false;
|
||||
bool recordSubmittedPreviousSession = false;
|
||||
|
||||
PracticeActivityEvent get practiceEvent => widget.practiceEvent;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
initalizeActivity();
|
||||
}
|
||||
|
||||
@override
|
||||
void didUpdateWidget(covariant PracticeActivityContent oldWidget) {
|
||||
super.didUpdateWidget(oldWidget);
|
||||
if (oldWidget.practiceEvent.event.eventId !=
|
||||
widget.practiceEvent.event.eventId) {
|
||||
initalizeActivity();
|
||||
}
|
||||
}
|
||||
|
||||
void initalizeActivity() {
|
||||
final PracticeActivityRecordEvent? recordEvent =
|
||||
widget.practiceEvent.userRecords.firstOrNull;
|
||||
if (recordEvent?.record == null) {
|
||||
recordModel = PracticeActivityRecordModel(
|
||||
question:
|
||||
widget.practiceEvent.practiceActivity.multipleChoice!.question,
|
||||
);
|
||||
} else {
|
||||
recordModel = recordEvent!.record;
|
||||
|
||||
//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;
|
||||
}
|
||||
setState(() {});
|
||||
}
|
||||
|
||||
void updateChoice(int index) {
|
||||
setState(() {
|
||||
selectedChoiceIndex = index;
|
||||
recordModel!.addResponse(
|
||||
text: widget
|
||||
.practiceEvent.practiceActivity.multipleChoice!.choices[index],
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
Widget get activityWidget {
|
||||
switch (widget.practiceEvent.practiceActivity.activityType) {
|
||||
case ActivityTypeEnum.multipleChoice:
|
||||
return MultipleChoiceActivity(
|
||||
card: this,
|
||||
updateChoice: updateChoice,
|
||||
isActive:
|
||||
!recordSubmittedPreviousSession && !recordSubmittedThisSession,
|
||||
);
|
||||
default:
|
||||
return const SizedBox.shrink();
|
||||
}
|
||||
}
|
||||
|
||||
void sendRecord() {
|
||||
MatrixState.pangeaController.activityRecordController
|
||||
.send(
|
||||
recordModel!,
|
||||
widget.practiceEvent,
|
||||
)
|
||||
.catchError((error) {
|
||||
ErrorHandler.logError(
|
||||
e: error,
|
||||
s: StackTrace.current,
|
||||
data: {
|
||||
'recordModel': recordModel?.toJson(),
|
||||
'practiceEvent': widget.practiceEvent.event.toJson(),
|
||||
},
|
||||
);
|
||||
return null;
|
||||
}).then((_) => widget.controller.showNextActivity());
|
||||
|
||||
setState(() {
|
||||
recordSubmittedThisSession = true;
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
debugPrint(
|
||||
"MessagePracticeActivityContentState.build with selectedChoiceIndex: $selectedChoiceIndex",
|
||||
);
|
||||
return Column(
|
||||
children: [
|
||||
activityWidget,
|
||||
const SizedBox(height: 8),
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Opacity(
|
||||
opacity: selectedChoiceIndex != null &&
|
||||
!recordSubmittedThisSession &&
|
||||
!recordSubmittedPreviousSession
|
||||
? 1.0
|
||||
: 0.5,
|
||||
child: TextButton(
|
||||
onPressed: () {
|
||||
if (recordSubmittedThisSession ||
|
||||
recordSubmittedPreviousSession) {
|
||||
return;
|
||||
}
|
||||
selectedChoiceIndex != null ? sendRecord() : null;
|
||||
},
|
||||
style: ButtonStyle(
|
||||
backgroundColor: WidgetStateProperty.all<Color>(
|
||||
AppConfig.primaryColor,
|
||||
),
|
||||
),
|
||||
child: Text(L10n.of(context)!.submit),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue