Save timestamp of selected choices

pull/1183/head
Kelrap 1 year ago
parent ddb17cb038
commit f03fa4f36e

@ -4,9 +4,8 @@
// SpanChoice of text in message from options
// Call to server for additional/followup info
import 'package:flutter/material.dart';
import 'package:collection/collection.dart';
import 'package:flutter/material.dart';
import '../enum/span_choice_type.dart';
import '../enum/span_data_type.dart';
@ -105,6 +104,7 @@ class SpanChoice {
required this.type,
this.feedback,
this.selected = false,
this.timestamp,
});
factory SpanChoice.fromJson(Map<String, dynamic> json) {
return SpanChoice(
@ -117,6 +117,8 @@ class SpanChoice {
: SpanChoiceType.bestCorrection,
feedback: json['feedback'],
selected: json['selected'] ?? false,
timestamp:
json['timestamp'] != null ? DateTime.parse(json['timestamp']) : null,
);
}
@ -124,12 +126,14 @@ class SpanChoice {
SpanChoiceType type;
bool selected;
String? feedback;
DateTime? timestamp;
Map<String, dynamic> toJson() => {
'value': value,
'type': type.name,
'selected': selected,
'feedback': feedback,
'timestamp': timestamp?.toIso8601String(),
};
String feedbackToDisplay(BuildContext context) {

@ -55,18 +55,36 @@ class SpanCardState extends State<SpanCard> {
// debugger(when: kDebugMode);
super.initState();
getSpanDetails();
// fetchSelected();
}
//get selected choice
SpanChoice? get selectedChoice {
if (selectedChoiceIndex == null ||
widget.scm.pangeaMatch?.match.choices == null ||
widget.scm.pangeaMatch!.match.choices!.length >= selectedChoiceIndex!) {
widget.scm.pangeaMatch!.match.choices!.length <= selectedChoiceIndex!) {
return null;
}
return widget.scm.pangeaMatch?.match.choices?[selectedChoiceIndex!];
}
void fetchSelected() {
if (widget.scm.pangeaMatch?.match.choices == null) {
return;
}
if (selectedChoiceIndex == null) {
DateTime? mostRecent;
for (int i = 0; i < widget.scm.pangeaMatch!.match.choices!.length; i++) {
final choice = widget.scm.pangeaMatch?.match.choices![i];
if (choice!.timestamp != null &&
(mostRecent == null || choice.timestamp!.isAfter(mostRecent))) {
mostRecent = choice.timestamp;
selectedChoiceIndex = i;
}
}
}
}
Future<void> getSpanDetails() async {
try {
if (widget.scm.pangeaMatch?.isITStart ?? false) return;
@ -110,6 +128,16 @@ class WordMatchContent extends StatelessWidget {
Future<void> onChoiceSelect(int index) async {
controller.selectedChoiceIndex = index;
controller
.widget
.scm
.choreographer
.igc
.igcTextData
?.matches[controller.widget.scm.matchIndex]
.match
.choices?[index]
.timestamp = DateTime.now();
controller
.widget
.scm
@ -152,6 +180,7 @@ class WordMatchContent extends StatelessWidget {
offset: controller.widget.scm.pangeaMatch?.match.offset,
);
}
final MatchCopy matchCopy = MatchCopy(
context,
controller.widget.scm.pangeaMatch!,

Loading…
Cancel
Save