我的分数来自Firebase,基本上是在映射问题时,当前问题的分数会添加到先前问题的分数中,因此在最后一个问题上,您将从同一问题中获得最终分数分数变量,它们是所有彼此相加的分数。
我的问题是,我如何才能实际获得最终分数(最后一个问题的score变量的结果)并将其保存在totalScore变量中,以便我可以打印topicTotal?
class AssessmentState with ChangeNotifier {
double _progress = 0;
Options _selected;
Options _score;
Options _topicTotal;
final PageController controller = PageController();
var idx = 0;
get progress => _progress;
get selected => _selected;
get score => _score;
get topicTotal => _topicTotal;
// calculates the score
set score(Options newValue) {
var score = idx += newValue.score;
var finalScore = score;
_score = newValue;
print(score);
_score = newValue;
notifyListeners();
}
//calculates the total score
set topicTotal(Options newValue) {
print(topicTotal);
notifyListeners();
}
class WellDonePage extends StatelessWidget {
final Assessment assessment;
final Questions questions;
final Options options;
WellDonePage({this.assessment, this.questions, this.options});
@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 score of has been stored in your carbon footprint bucket.',
style: greySubTxt,
textAlign: TextAlign.center,
),
SizedBox(height: 40),
Image.asset('assets/well_done.gif'),
Divider(),
Padding(
padding: const EdgeInsets.symmetric(vertical: 40, horizontal: 20),
child: FlatButton.icon(
color: lightGrey,
icon: Icon(FontAwesomeIcons.check, color: deepGrey),
label: Text(' Mark Complete!', style: greyHead2Txt),
onPressed: () {
// PRINT THE TOPIC TOTAL SCORE HERE