【问题标题】:Flutter - Determinate Loading in FutureBuilderFlutter - 在 FutureBuilder 中确定加载
【发布时间】:2021-11-30 23:15:39
【问题描述】:

我有一个案例,我正在使用FutureBuilder,在加载时我显示我的CircularProgressIndicator。现在我想为加载程序设置一个值,但我没有,而且我真的没有办法知道完成未来需要多少时间。我当前的代码是这样的:

FutureBuilder(
  future: getSoilData(context),
  builder: (BuildContext context, snapshot) {
    if (snapshot.connectionState == ConnectionState.done) {
    return makeBody();
    }
    
    return LoadingBar();
  },
),

那么,我该如何设置进度条的值,以便用户了解加载器还需要多长时间。

【问题讨论】:

标签: flutter progress-bar flutter-futurebuilder


【解决方案1】:

ConnectionState 等待

if (snapshot.connectionState == ConnectionState.done) {
    return makeBody();
    }
else if (snapshot.connectionState == ConnectionState.waiting) {
    return LoadingBar();
  },

或者你可以放一个 else

if (snapshot.connectionState == ConnectionState.done) {
    return makeBody();
    }
else {
    return LoadingBar();
  },

【讨论】:

  • 这就是我目前正在做的事情。我想将值添加到加载栏,以便用户了解需要多长时间。
猜你喜欢
  • 2021-11-29
  • 2023-03-21
  • 2021-11-25
  • 2020-03-22
  • 2022-01-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-02-06
相关资源
最近更新 更多