如何更新从扑动中从未来的杂乱器中获取的数据?
在我的应用程序中,我有一个包含3个不同的构建者的屏幕,我想更新从未来构建器中恢复的数据。我尝试了SetState()方法,但是这会更新页面上的所有3个未来构建器,我只需要更新一个即可。我该怎么办?
我的3个未来建筑商这样的结构是这样:
FutureBuilder(
future: getData(), //Fetch the data
builder:
(context, AsyncSnapshot snapshot) {
if (snapshot.connectionState == ConnectionState.done) {
return Text('${snapshot.data}',
style: const TextStyle(
fontSize: 15,
color: Colors.black));
} else {
return const CircularProgressIndicator.adaptive();
}
})
In my app I have a screen which contains 3 different future builders, I would like to update the data recovered from a future builder. I tried the setState () method but this updates all 3 future builders on the page, I only need to update one. How can I do ?
My 3 future builders are structured like this:
FutureBuilder(
future: getData(), //Fetch the data
builder:
(context, AsyncSnapshot snapshot) {
if (snapshot.connectionState == ConnectionState.done) {
return Text('${snapshot.data}',
style: const TextStyle(
fontSize: 15,
color: Colors.black));
} else {
return const CircularProgressIndicator.adaptive();
}
})
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您只想重建屏幕的一部分,则可以使用
statefulbuilder
。包装单个
futurebuilder
您想使用statefulbuilder
喜欢重建,例如:如果
setState
从statefunfulbuilder
中调用,只有用statefulbuilder
包装的屏幕部分才会进行重建。If you want to rebuild just a portion of your screen, you can use
StatefulBuilder
.Wrap the single
FutureBuilder
you want to rebuild with aStatefulBuilder
like so:If
setState
is called from inside theStatefulBuilder
, only the portion of the screen that is wrapped with theStatefulBuilder
will be rebuilt.SetState将始终重建您的页面。请使用状态管理插件,例如GetX,提供商的某些部分更新。
Setstate will always rebuild your page. please use State management plugins like getx,provider for some portion update.