这个问题在这里已有答案: 动态创建元素的事件绑定? 23个答案 我有一个表单,我用它来使用ajax和php插入数据 我已经按照我想要的方式工作,但我想对它做一些调整,下面是我想说的 原来 在默认情况下在页面上加载按钮时有效 我想做的调整是 ...
提示:本站收集StackOverFlow近2千万问答,支持中英文搜索,鼠标放在语句上弹窗显示对应的参考中文或英文, 本站还提供 中文简体 中文繁体 英文版本 版本,有任何建议请联系yoyou2525@163.com。
After updating this line in Future builder在 Future builder 中更新此行后
Container(
child: FutureBuilder<DocumentSnapshot>(
future: FirebaseFirestore.instance
.collection("users")
.doc(RitechApp.sharedPreferences
.getString(RitechApp.userUID))
.get(),
builder: (c, snapshot) {
if (!snapshot.hasData)
return Center(
child: CircularProgressIndicator(
valueColor:
new AlwaysStoppedAnimation<Color>(
kPrimaryColor),
),
);
else {
return Text(
"KES" +
snapshot..data.data["Wallet"]
.toString() ??
0.toString(),
style: TextStyle(
fontSize: 25,
fontFamily: "Muli",
color: Colors.white),
);
}
},
),
),
This following firebase database update and as well as observing null safety rules, I'm unable to retrieve wallet balance or update with each transaction.在 firebase 数据库更新以及遵守 null 安全规则之后,我无法检索钱包余额或更新每笔交易。 This is the code:这是代码:
Container(
child: FutureBuilder<DocumentSnapshot>(
future: FirebaseFirestore.instance
.collection("users")
.doc(RitechApp.sharedPreferences
.getString(RitechApp.userUID))
.get(),
builder: (c, snapshot) {
if (!snapshot.hasData)
return Center(
child: CircularProgressIndicator(
valueColor:
new AlwaysStoppedAnimation<Color>(kPrimaryColor),
),
);
else {
return Text(
"KES" + snapshot.data!["Wallet"].toString() ??
0.toString(),
style: TextStyle(
fontSize: 25,
fontFamily: "Muli",
color: Colors.white),
);
}
},
),
),
I'm unable to retrieve wallet balance or update with each transaction.我无法检索钱包余额或更新每笔交易。 This is the code.这是代码。
Create a state variable for future like为未来创建一个 state 变量
late final myFuture = FirebaseFirestore.instance
.collection("users")
.doc(RitechApp.sharedPreferences.getString(RitechApp.userUID))
.get();
and use FutureBuiler like this, you will get error message if something fails并像这样使用 FutureBuiler,如果出现故障,您将收到错误消息
child: FutureBuilder<DocumentSnapshot?>(
future: myFuture,
builder: (c, snapshot) {
if (snapshot.hasData) {
//
return Text(
// "KES ${snapshot.data?["Wallet"] ?? 0} ",
"KES ${snapshot.data?.get("Wallet") ?? 0}",
style: TextStyle(
fontSize: 25, fontFamily: "Muli", color: Colors.white),
);
} else if (snapshot.hasError) {
return Text(" ${snapshot.error}");
} else {
return Center(
child: CircularProgressIndicator(
valueColor: new AlwaysStoppedAnimation<Color>(Colors.red),
),
);
}
},
),
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.