【问题标题】:Flutter listview item disappear when scrollingFlutter listview 项目在滚动时消失
【发布时间】:2020-04-28 02:15:24
【问题描述】:

我将许多 Listile 小部件放入我的 Listview 中,我在我的物理 IOS 设备上调试应用程序,当我快速向上滚动列表视图时,当它几乎到达列表视图顶部时,列表项突然消失,正文区域为空, 任何人都知道如何解决这个问题?提前致谢。

代码:

    return Scrollbar(
      child:ListView.builder(
        key: const PageStorageKey("list1"),
        cacheExtent: 999999,
        itemCount: _peddingContacts.length,
        padding: const EdgeInsets.all(8),
        itemBuilder: (BuildContext context,int index){
            if(index.isOdd){
              return Divider();
            }
            final idx = index ~/ 2;
            return _buildRow(_peddingContacts.elementAt(idx), 0, idx);
        })
      );
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, v1.12.13+hotfix.9, on Mac OS X 10.15.4 19E287, locale zh-Hans-CN)

[!] Android toolchain - develop for Android devices (Android SDK version 29.0.3)
    ! Some Android licenses not accepted.  To resolve this, run: flutter doctor --android-licenses
[✓] Xcode - develop for iOS and macOS (Xcode 11.4.1)
[!] Android Studio (version 3.6)
    ✗ Flutter plugin not installed; this adds Flutter specific functionality.
    ✗ Dart plugin not installed; this adds Dart specific functionality.
[✓] VS Code (version 1.44.2)
[✓] Proxy Configuration
[✓] Connected device (2 available)

! Doctor found issues in 2 categories.

【问题讨论】:

  • 为什么你把一个列表视图放在可滚动的里面它没有意义因为列表视图是可滚动的我认为删除它可以解决你的问题或把它放在固定大小的小部件
  • 因为我想让listview显示一个滚动条。我尝试添加固定大小的小部件,但它不起作用。
  • 所以我认为你应该在 ListView.builder 中添加shrinkWrap: true。 (参考:api.flutter.dev/flutter/widgets/ScrollView/shrinkWrap.html)。
  • 谢谢,我设置了shrinkWrap 后就好了。

标签: listview flutter


【解决方案1】:

Flutter ListView 可以重绘以前在其视口上不可见的项目。如果要渲染的 ListView 项目包含大量 Widget,则在快速滚动时可能会导致渲染过程中出现一些延迟。这是来自 Flutter 的 informational video,讨论了视口的工作原理。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-07
    • 2015-09-13
    • 1970-01-01
    • 2015-04-27
    • 1970-01-01
    相关资源
    最近更新 更多