【问题标题】:Flutter/Dart - Transparent Background until Future arrives?Flutter/Dart - 透明背景直到未来到来?
【发布时间】:2020-12-16 14:50:38
【问题描述】:

我正在尝试获取使用来自网络的数据构建的PageView.Builder。当我尝试从另一个页面滑动到它时,我得到一个白色背景,它似乎充当占位符,直到来自 Future 的网络数据到达。我想要的是原始页面在页面构建之前保持在后台可见。但是,尽管我已经尝试了我能想到的一切,但在Future 到达填充PageView 之前,背景仍然是白色的。在到达之前,我如何才能获得清晰或至少降低不透明度的占位符?

我使用了 CircularProgressIndicator 作为占位符,但它不仅看起来很糟糕(滑动会将其从各个方向炸开),而且背景仍然顽固地不透明和白色。我还尝试了带有透明颜色的Container,但这只是覆盖了未来的白色背景。我怎样才能摆脱像Future 的占位符一样的不透明白色背景?

这就是未来;

FutureBuilder<List<ReplyContent>> replyStage({String replyid}) {
  return FutureBuilder<List<ReplyContent>>(
    future: downloadReplyJSON(replyid),
    builder: (context, snapshot) {
      if (snapshot.hasData) {
        List<ReplyContent> replycrafts = snapshot.data;
        return StageBuilderVR(replycrafts, Globals.masterTitle);
      } else if (snapshot.hasError) {
        return Text('${snapshot.error}');
      }
      return
        Container(
         color: Colors.transparent,
        );
    }
  );
}

【问题讨论】:

    标签: flutter dart future flutter-pageview


    【解决方案1】:

    因此,我决定完全采用不同的方法,并创建了一个虚拟页面,它以图形方式镜像上一页,其中包含上一页的所有图形元素,但没有任何代码。我用这个假人代替了 CircularProgressIndicator。这可能不是正确或最好的方法,但它似乎运作良好。我对结果很满意。

    FutureBuilder<List<ReplyContent>> replyStage({String replyid, String replytitle}) {
      return new FutureBuilder<List<ReplyContent>>(
        future: downloadReplyJSON(),
        builder: (context, snapshot) {
          if (snapshot.hasData) {
            List<ReplyContent> replycrafts = snapshot.data;
            return StageBuilderVR(replycrafts, replytitle);
          } else if (snapshot.hasError) {
            return Text('${snapshot.error}');
          }
          return DummyPage();
        },
      );
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-09-11
      • 1970-01-01
      • 1970-01-01
      • 2011-03-08
      • 1970-01-01
      • 1970-01-01
      • 2018-10-25
      • 1970-01-01
      相关资源
      最近更新 更多