【问题标题】:How to fix duplicate error on ListView after click Back button?单击后退按钮后如何修复 ListView 上的重复错误?
【发布时间】:2019-04-16 09:48:49
【问题描述】:

仅在单击后退按钮后才会发生重复。

我在 github 上上传了完整的 listview 代码。 listview code

【问题讨论】:

    标签: dart flutter flutter-layout


    【解决方案1】:

    好像

    Widget createListView(BuildContext context, AsyncSnapshot snapshot) {
    
    // ... 
    
          children: List.generate(values.length, (index) {
    

    长度错误。

    请注意,您的 build 方法可以随时被调用(当您导航时它肯定会被调用)。

    所以你的

    getRegister1() 
    

    被多次调用,因此您需要进一步研究此方法,因为未提供 HelperDatabase1 背后的代码。

    (也许这是你的问题...

    var catLocal = (await HelperDatabase1().displayDefCatRelation())
    var defCatLocal = (await HelperDatabase1().display()) +
    
    cat.add(catLocal[i].c);  // maybe this actually saves in your db/cache
    

    但我不能确定 )


    您应该查看的另一件事是您的 getRegister1() 应该是“以前获得的”。 检查来自flutter docs的这个sniper。

    FutureBuilder<String>(
      future: _calculation, // a previously-obtained Future<String> or null
      builder: (BuildContext context, AsyncSnapshot<String> snapshot) {
        switch (snapshot.connectionState) {
          case ConnectionState.none:
            return Text('Press button to start.');
          case ConnectionState.active:
          case ConnectionState.waiting:
            return Text('Awaiting result...');
          case ConnectionState.done:
            if (snapshot.hasError)
              return Text('Error: ${snapshot.error}');
            return Text('Result: ${snapshot.data}');
        }
        return null; // unreachable
      },
    )
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-03-04
      • 2016-03-27
      • 2011-01-25
      • 1970-01-01
      • 1970-01-01
      • 2011-09-15
      • 1970-01-01
      相关资源
      最近更新 更多