【发布时间】:2021-02-22 17:31:17
【问题描述】:
我在状态中设置了score、topicTotal 和level,我正在打印它们中的每一个。 topicTotal 是所有分数相加的最终分数,level 是基于他们的topicTotal。
score 来自 Firebase 的每个问题。我想根据score 的总和计算总分,我想根据总分向用户显示一个级别。
尽管我可以打印score、topicTotal 和level,但我无法向用户显示这些值。
如何向用户显示这些值,如果无法从状态中显示它们,如何使用不同的方法检索和显示它们?
class AssessmentState with ChangeNotifier {
double _progress = 0;
Options _selected;
dynamic _score;
dynamic _topicTotal;
final PageController controller = PageController();
var idx = 0;
get progress => _progress;
get selected => _selected;
get score => _score;
get topicTotal => _topicTotal;
set progress(double newValue) {
_progress = newValue;
notifyListeners();
}
set selected(Options newValue) {
_selected = newValue;
notifyListeners();
}
set score(dynamic newValue) {
var score = idx += newValue.score;
_score = newValue;
print(score);
_score = newValue;
notifyListeners();
}
set topicTotal(dynamic newValue) {
var topicTotal = idx;
print(topicTotal);
if (topicTotal <= 300) {
print('Level 1');
} else if (topicTotal <= 900) {
print('Level 2');
} else if (topicTotal <= 1400) {
print('Level 3');
} else
print('Level 4');
notifyListeners();
}
final Assessment assessment;
final Questions questions;
final Options options;
final Options optionSelected;
WellDonePage({this.assessment, this.questions, this.options, this.optionSelected});
@override
Widget build(BuildContext context) {
var state = Provider.of<AssessmentState>(context);
return Padding(
padding: EdgeInsets.all(20),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
'Well Done! You completed the ${assessment.title} Assessment. Your level for the ${assessment.title} Assessment is ${state.topicTotal}',
【问题讨论】: