滚动后如何防止ListView.builder中的项目重新呈现?

时间:2020-09-05 05:43:29

标签: flutter listview keep-alive

我有一个ListView.builder(),我不希望它的项目重新呈现,我尝试了此解决方案Solution 但是什么也没发生,它一直在重新渲染,所以我不知道出了什么问题。

代码

StreamBuilder<Object>(
        stream: Firestore.instance
            .collection('Khatma Collection')
            .document('Khatma 1')
            .collection('Videos')
            .snapshots(),
        builder: (context, AsyncSnapshot snapshot) {
          if (snapshot.hasData) {
            return ListView.builder(
          shrinkWrap: true,
          itemCount: snapshot.data.documents.length,
          itemBuilder: (context, i) {
            var rng = new Random();
            int ii = rng.nextInt(4);
            if (ii == iii) {
            } else {
              iii = ii;
              var link = snapshot.data.documents[ii].data['Link'];
              var uploader = snapshot.data.documents[ii].data['Uploader'];
              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,
                    ),
                    ),
                  ],
                ),
              );
            }
          },
        );

3 个答案:

答案 0 :(得分:0)

您可以尝试...

addRepaintBoundaries: false,

答案 1 :(得分:0)

改为使用ListView()Column小部件

答案 2 :(得分:0)

在 Listview.builder 中使用此属性: addAutomaticKeepAlives: 真