gpt4 book ai didi

firebase - Flutter:向用户显示总分/等级

转载 作者:行者123 更新时间:2023-12-03 20:47:49 27 4
gpt4 key购买 nike

我在状态中设置了 scoretopicTotallevel,我正在打印它们中的每一个。 topicTotal 是所有分数相加的最终分数,level 基于它们的 topicTotal

score 来自每个问题的 Firebase。我想根据 score 的总和计算总分,并根据总分向用户显示一个级别。

尽管我能够打印scoretopicTotallevel,但我无法向用户显示这些值。

我如何向用户显示这些值,如果我不能从状态中显示它们,我如何使用不同的方法检索和显示它们?

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}',

最佳答案

您可以使用构建器方法像这样

StreamBuilder<QuerySnapshot>(
stream: Firestore.instance.collection('DriverList').snapshots(),
builder: (BuildContext context, AsyncSnapshot<QuerySnapshot> snapshot) {
if (!snapshot.hasData) return new Text('Loading...');
return new ListView(
children: snapshot.data.documents.map((DocumentSnapshot document) {
return new ListTile(
title: new Text(document['name']),
subtitle: new Text(document['phone']),
);
}).toList(),
);
},
);

关于firebase - Flutter:向用户显示总分/等级,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64774641/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com