Merge pull request #310 from pangeachat/save-selection
Save span card selection
This commit is contained in:
commit
81ec46ed4d
2 changed files with 35 additions and 2 deletions
|
|
@ -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,6 +55,7 @@ class SpanCardState extends State<SpanCard> {
|
|||
// debugger(when: kDebugMode);
|
||||
super.initState();
|
||||
getSpanDetails();
|
||||
fetchSelected();
|
||||
}
|
||||
|
||||
//get selected choice
|
||||
|
|
@ -67,6 +68,23 @@ class SpanCardState extends State<SpanCard> {
|
|||
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…
Add table
Reference in a new issue