Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/flutter/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/dart/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Flutter 颤振-ListView.builder不可滚动_Flutter_Dart_Google Cloud Firestore - Fatal编程技术网

Flutter 颤振-ListView.builder不可滚动

Flutter 颤振-ListView.builder不可滚动,flutter,dart,google-cloud-firestore,Flutter,Dart,Google Cloud Firestore,我有我的ListView.builder内部扩展的小部件,可以在屏幕上正确呈现小部件,但我无法滚动它呈现的小部件 Widget build(BuildContext context) { return Container( child: FutureBuilder( future: getPostsForUid(), builder: (_, snap) { return Expanded( chi

我有我的
ListView.builder
内部
扩展的
小部件,可以在屏幕上正确呈现小部件,但我无法滚动它呈现的小部件

 Widget build(BuildContext context) {
    return Container(
      child: FutureBuilder(
        future: getPostsForUid(),
        builder: (_, snap) {
          return Expanded(
            child: ListView.builder(
              physics: NeverScrollableScrollPhysics(),
              shrinkWrap: true,
              itemCount: snap.data.length,
              itemBuilder: (_, index) {
                if (snap.data[index]['post_type'] == 'real_estate') {
                  return realEstate(snap, index);
                }
                else if (snap.data[index]['post_type'] == 'video_sharing') {
                  return videoSharing(snap, index);
                }
                else {
                  return Text('');
                }
              },
            ),
          );
        },
      ),
    );
  }

列表视图中添加
物理:AlwaysScrollable()

尝试使用ScrollPhysics()类,
物理学:滚动物理学()

以下是相同的参考。

您应该将物理设置为
AlwaysScrollableScrollPhysics()
。 文件规定如下:

滚动始终允许用户滚动的物理。 这将覆盖默认行为,即在没有要滚动的内容时禁用滚动。它不会覆盖过卷的处理。 在Android上,默认情况下,过卷将被钳制,并导致过卷发光。在iOS上,overscrolls将加载一个弹簧,当释放时,该弹簧将使滚动视图返回其正常范围

下面是一张“超卷发光”的图片,让您了解这意味着什么。

考虑使用
shrinkWrap:false
扩展内容,以防它们被绑定

Widget build(BuildContext context) {
    return Container(
      child: FutureBuilder(
        future: getPostsForUid(),
        builder: (_, snap) {
          return Expanded(
            child: ListView.builder(
              physics: AlwaysScrollableScrollPhysics(),
              shrinkWrap: true,
              itemCount: snap.data.length,
              itemBuilder: (_, index) {
                if (snap.data[index]['post_type'] == 'real_estate') {
                  return realEstate(snap, index);
                }
                else if (snap.data[index]['post_type'] == 'video_sharing') {
                  return videoSharing(snap, index);
                }
                else {
                  return Text('No data available.');
                }
              },
            ),
          );
        },
      ),
    );
  }
见文件:


已添加但仍不可滚动。@zrhl您的listview高度是否大于视口高度?如果您的内容有边界,您可能需要
包覆面提取:false
。将AlwaysScrollableScrollPhysics()和shrinkWrap添加到false时不会渲染任何窗口小部件all@zrhl请确保这不是由于您的
else
案例呈现空文本造成的。我在回答中修改了代码以适应这种情况。@zrhl您是否测试了您的代码是否产生了else情况?