为什么我的ListView.builder()无法滚动?

时间:2020-09-01 06:25:58

标签: flutter google-cloud-firestore scroll

我之前曾问过一种方法,该方法可以从Firebase中获取索引为“视频的链接”的所有信息,但是现在,当这些视频超出模拟器边界时,它会抛出overflow with x pixels,因此我尝试放置它在SingleChildScrollView中不起作用,并且ListView.builder()中的属性shrinkWrap应该建立一个可滚动的List,但显然不需要帮助。

代码

return Container(
      child: StreamBuilder<Object>(
        stream: Firestore.instance
            .collection('Khatma Collection')
            .document('Khatma 1')
            .collection('Videos')
            .snapshots(),
        builder: (context, AsyncSnapshot snapshot) {
          if (snapshot.hasData) {
            return SingleChildScrollView(
              child: ListView.builder(
                shrinkWrap: true,
                itemCount: snapshot.data.documents.length,
                itemBuilder: (context, i) {
                  var link = snapshot.data.documents[i].data['Link'];
                  var uploader = snapshot.data.documents[i].data['Uploader'];
                  var likes = snapshot.data.documents[i].data['Likes'];
                  var like = likes.toString();
                  bool liked;
                  print({link, uploader, likes});
                  if (int.parse(like) > 0) {
                    liked = true;
                  } else if (int.parse(like) == 0) {
                    liked = false;
                  }
                  final videoPlayerController =
                      VideoPlayerController.network(link);
                  chewieController = ChewieController(
                    allowMuting: true,
                    autoInitialize: true,
                    deviceOrientationsAfterFullScreen: orientation,
                    allowFullScreen: true,
                    aspectRatio: 16 / 9,
                    videoPlayerController: videoPlayerController,
                  );
                  return SingleChildScrollView(
                    child: Column(
                      children: [
                        Chewie(
                          controller: chewieController,
                        ),
                        Container(
                          margin:
                              EdgeInsets.only(top: 10, left: 10, bottom: 30),
                          child: Row(
                            children: [
                              Text(
                                '$uploader',
                                style: TextStyle(
                                  fontSize: 20,
                                  fontWeight: FontWeight.bold,
                                  foreground: Paint()..shader = linearGradient,
                                ),
                              ),
                              Container(
                                margin: EdgeInsets.only(left: 200),
                                child: LikeButton(
                                  likeCount: int.parse(like),
                                  isLiked: liked,
                                ),
                              ),
                            ],
                          ),
                        ),
                      ],
                    ),
                  );
                },
              ),
            );
          }
          return Center(
            child: CircularProgressIndicator(),
          );
        },
      ),
    );

3 个答案:

答案 0 :(得分:3)

   body: Container(
          child: SingleChildScrollView(
            child: Container(
              height: 200, //maybe add a parent widget so it will have a height
              child: ListView.builder(
                  itemCount: 100,
                  itemBuilder: (_, index) {
                    return Text("$index");
                  }),
            ),
          )),

答案 1 :(得分:1)

physics: NeverScrollableScrollPhysics()添加到ListView.Builder

 ListView.builder(
            shrinkWrap: true,
            physics: NeverScrollableScrollPhysics(),

答案 2 :(得分:0)

我发现了问题,我正在使用mediaQuery来识别高度,但它需要这样的数字 Container( height: 200 ), 不像Container( height: height * n )