首页 > 解决方案 > 如何提高 `ListView.builder` 的性能?

问题描述

我有一个ListView.builder从firebase构建视频的东西,它工作正常,但是当我上下很多次所以它重建时,视频抛出一个错误,我认为这是因为listview.builder,有什么想法可以防止这种情况吗?

代码

StreamBuilder(
  stream: _store
      .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 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;
          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 link != null
              ? SingleChildScrollView(
                  child: Column(
                    children: [
                      Chewie(
                        controller: chewieController,
                      ),
                    ],
                  );

              ...

标签: androidperformanceflutterlistviewstream

解决方案


推荐阅读