我是新手,对上述内容有挑战。
我从FireStore检索有关多个对象/文档的数据,并创建ListView。
逻辑或缺乏逻辑如下:
Container
StreamBuilder
ListView
Container
Rows, Columns, Text and whatever to display each document from StreamBuilder.
此ListView包含多个容器,其中每个容器显示来自一个对象的数据。每个容器中都有一个TextFormField,它需要一个双精度值。基于此值,我想更改同一容器内的Text()-计算。
这可能吗?如果是这样-如何?我知道我可以以某种方式使用TextEditController,但是tha计算的结果将是可编辑的。还是?
return new ListView(//
children: getMedicationItem(asyncSnapshot
shrinkWrap: true,
children: asyncSnapshot.data.documents.map((DocumentSnapshot document) {
MyObject object = new MyObject(document, integerValue);
backgroundColor = !backgroundColor;
return new Container(
color: backgroundColor? Colors.black26: Colors.white,
child: new Row(
children: <Widget>[
new Flexible(
child: TextFormField(
onChanged: (text) {
double calculation = 0.0;
if (text.length > 0)
calculation = double.tryParse(text) * 23;
**UPDATE "$calculation" in Text() below**
},
keyboardType: TextInputType.number,
inputFormatters: [_decimal_validator],
)
),
new Flexible(
child: Text("$calculation"),
)
]
),
);
}
).toList(),
)
);
答案 0 :(得分:1)
您需要做的就是使用setState
告诉Flutter变量已更改,并且您希望重建使用该变量的所有Widget:
if (text.length > 0){
setState((){
calculation = double.tryParse(text) * 23;
});
}