Flutter-web:未来不会更改变量
我已经在flutter页面中了这个代码。
该代码应该向用户显示他的订单已发送到数据库。
我在功能上使用未来。
有人知道为什么我的_textinfo字符串变量不会将未来视为新价值吗?
Container(
padding: const EdgeInsets.all(Pages.edgeInsetsAll),
child: ElevatedButton(
onPressed: () {
setState(() {
for (int i = 0; i < myb.length; i++) {
if (myb[i].count > 1) {
for (int j = 0; j < myb[i].count; j++) {
postOrder(
widget.basketId,
Session.sessionQRCode,
"Pas Membre",
"Especes",
Session.sessionEstaName,
myb[i].price,
myb[i].product,
myb[i].add).then((value) {
_textInfo = 'ORDER : $value';
});
}
} else {
postOrder(
widget.basketId,
Session.sessionQRCode,
"Pas Membre",
"Especes",
Session.sessionEstaName,
myb[i].price,
myb[i].product,
myb[i].add).then((value){
_textInfo= 'ORDER : $value';
});
}
}
myb.clear();
});
},
child: Text(_textInfo)),
),
I've this code in a Flutter page.
This code is supposed to show to the user that his orders had been send to the database.
I use a future with the function .then and I should get the response status code 200 which is printed in the debug console of my app.
Does someone know why my _textInfo String variable doesn't take the future as new value ?
Container(
padding: const EdgeInsets.all(Pages.edgeInsetsAll),
child: ElevatedButton(
onPressed: () {
setState(() {
for (int i = 0; i < myb.length; i++) {
if (myb[i].count > 1) {
for (int j = 0; j < myb[i].count; j++) {
postOrder(
widget.basketId,
Session.sessionQRCode,
"Pas Membre",
"Especes",
Session.sessionEstaName,
myb[i].price,
myb[i].product,
myb[i].add).then((value) {
_textInfo = 'ORDER : $value';
});
}
} else {
postOrder(
widget.basketId,
Session.sessionQRCode,
"Pas Membre",
"Especes",
Session.sessionEstaName,
myb[i].price,
myb[i].product,
myb[i].add).then((value){
_textInfo= 'ORDER : $value';
});
}
}
myb.clear();
});
},
child: Text(_textInfo)),
),
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论