我是 Flutter 的新手,我无法在 futureBuilder 范围之外的小部件中显示 snapshot.data 值,可以这样做吗?如果不是,那么更好的方法是什么?
//...
var result = '0.00';
Row(children: [
const Text('RESULT: '),
FutureBuilder(
future: Obj.mapaProvider(widget
.property1
.toString()),
builder: (context, snapshot) {
if (snapshot.connectionState == ConnectionState.done) {
result = snapshot.data.toString();
return Text(
result,
style: const TextStyle(
fontWeight: FontWeight.bold,
),
);
} else {
return const Text("WITHOUT RESULT");
}
}),
]),
const Divider(
height: 20,
thickness: 5,
),
// In this widget need the new value of result variable from futurebuilder snapshot.data
OtherWidget(result), // PERHAPS SHOWS 0,00 **
//...