52 lines
1.4 KiB
Dart
52 lines
1.4 KiB
Dart
import 'package:flutter/material.dart';
|
|
|
|
import '../models/incoming_question.dart';
|
|
import 'spelling_question_tile.dart';
|
|
import 'swipe_question_tile.dart';
|
|
|
|
/// Routes an [IncomingQuestion] to the correct presentation widget.
|
|
class QuestionPresentationRouter extends StatelessWidget {
|
|
const QuestionPresentationRouter({
|
|
super.key,
|
|
required this.question,
|
|
required this.onAnswer,
|
|
required this.onDefer,
|
|
this.onAnswerText,
|
|
this.onPrepared,
|
|
this.busy = false,
|
|
});
|
|
|
|
final IncomingQuestion question;
|
|
final Future<void> Function(num answer) onAnswer;
|
|
final Future<void> Function(String answerText)? onAnswerText;
|
|
final ValueChanged<IncomingQuestion>? onPrepared;
|
|
final Future<void> Function() onDefer;
|
|
final bool busy;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
if (question.usesSpellingWordTile) {
|
|
return SpellingQuestionTile(
|
|
key: ValueKey<String>(question.id),
|
|
questionId: question.id,
|
|
questionText: question.text,
|
|
spokenWord: question.spokenWord,
|
|
audioTitle: question.audioTitle,
|
|
needsPrepare: question.needsPrepare,
|
|
busy: busy,
|
|
onSubmitAnswer: onAnswerText ?? (_) async {},
|
|
onPrepared: onPrepared,
|
|
onDefer: onDefer,
|
|
);
|
|
}
|
|
|
|
return SwipeQuestionTile(
|
|
key: ValueKey<String>(question.id),
|
|
questionId: question.id,
|
|
busy: busy,
|
|
onSwipeRight: onAnswer,
|
|
onSwipeLeft: onDefer,
|
|
);
|
|
}
|
|
}
|