如何更新从扑动中从未来的杂乱器中获取的数据?

发布于 2025-01-21 13:17:45 字数 516 浏览 4 评论 0原文

在我的应用程序中,我有一个包含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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

沉默的熊 2025-01-28 13:17:45

如果您只想重建屏幕的一部分,则可以使用statefulbuilder
包装单个futurebuilder您想使用statefulbuilder喜欢重建,例如:

StatefulBuilder(
 builder: (context, setState) {
  return YourFutureBuilder();
 },
)

如果setStatestatefunfulbuilder中调用,只有用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 a StatefulBuilder like so:

StatefulBuilder(
 builder: (context, setState) {
  return YourFutureBuilder();
 },
)

If setState is called from inside the StatefulBuilder, only the portion of the screen that is wrapped with the StatefulBuilder will be rebuilt.

你又不是我 2025-01-28 13:17:45

SetState将始终重建您的页面。请使用状态管理插件,例如GetX,提供商的某些部分更新。

Setstate will always rebuild your page. please use State management plugins like getx,provider for some portion update.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文