【问题标题】:Scrolling Widgets like one Dashboard - FLUTTER像一个仪表板一样滚动小部件 - FLUTTER
【发布时间】:2018-07-31 11:49:48
【问题描述】:

我正在尝试构建一个包含一些报告的屏幕,就像Dashboard,我将手指向下移动并显示一些信息,例如向下滚动时Facebook

new CustomScrollView(
            slivers: [
              new SliverList(
                  delegate: new SliverChildListDelegate(
                      [
                        new RelatorioVendPeriodoAPeriodo(),
                        new RelatorioMensals(),
                        new RelatorioDiasDaSemanas(),
                        new RelatorioVendasTotalidasPorPeriodo(),
                        new RelatorioDasVendasTotsProdutos(),
//                        new RelatorioContaAssinadaCliente(),
                      ]
                  )
              )
            ]
        ),

它运行良好,BUT 当我向下滚动我已经看到消失的报告时。当我的报告消失时,我需要再次RELOAD 它,并且我通过 Json 请求获得此报告。

我想做一个仪表板,在这个例子中,加载 5 个请求,当我上去时,报告仍然加载在那里。

【问题讨论】:

  • 存储不在屏幕上的小部件可能会导致额外的内存使用。为什么不将 JSON 响应存储在父小部件中(例如 CustomScrollView)并在子小部件中使用它?
  • @Yamin,美好的一天,我该怎么做?我试过了:cacheExtent: 100000.0,效果很好,但是你还有别的想法吗?
  • 有两种方法可以实现这个目标。更新你的问题,把当前小部件的完整代码和调用后端的服务放在一起。我会在下面给出我的答案。

标签: json dart flutter dashboard


【解决方案1】:

我用这段代码解决了这个问题:

new CustomScrollView(
          cacheExtent: height * 5,
            slivers: [
              new SliverList(
                  delegate: new SliverChildListDelegate(
                    [
                      new RelatorioVendPeriodoAPeriodo(),
//                      new RelatorioMensals(),
                      new RelatorioDiasDaSemanas(),
                      new RelatorioVendasTotalidasPorPeriodo(),
                      new RelatorioDasVendasTotsProdutos(),
//                        new RelatorioContaAssinadaCliente(),
                    ]
                  )
              )
            ]
        ),

cacheExtent: height * 5, -> 救了我的代码。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-07-16
    • 1970-01-01
    • 1970-01-01
    • 2014-04-02
    • 1970-01-01
    • 2021-06-28
    • 1970-01-01
    • 2013-11-05
    相关资源
    最近更新 更多