代码之家  ›  专栏  ›  技术社区  ›  BIS Tech

加载大量图像时,低性能设备上的应用程序崩溃

  •  1
  • BIS Tech  · 技术社区  · 5 年前

    加载大量图像时,颤振应用程序崩溃。(仅应用程序崩溃低性能设备。例如:小米9c 2GB)。我两个都试过了 FadeInImage.memoryNetwork 和 CachedNetworkImage .

    有时长度超过1000,有时长度为20-30。总是在低性能设备上崩溃

    SliverGrid(
          gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(),
          childCount: model.length,
          delegate: SliverChildBuilderDelegate(
              (BuildContext context, int index) {
                     return AspectRatio(
                       aspectRatio: childAspectRatio,
                       child: FadeInImage.memoryNetwork(
                                  placeholder: kTransparentImage,
                                  image: model[index].imageUrl,
                                  fit: BoxFit.cover),
    
                                //   CachedNetworkImage(
                                //     placeholder: (context, url) => Container(),
                                //     errorWidget: (context, url, error) =>Container(),
                                //     imageUrl: model[index].imageUrl,
                                //     fit: BoxFit.fill,
                                //   )
    

    2 回复  |  直到 5 年前
        1
  •  0
  •   Usman Akhlaq    5 年前

    更好的方法是在开始时使用分页加载更少的图像。一次加载如此大量的图像对于旧设备来说是很困难的,因此更好的方法是加载50个图像,在到达屏幕末端时加载下一个50个。这样,即使对于低端设备,负载也可以维护。

        2
  •  0
  •   Igor L Sambo    5 年前

    您可能希望在将来尝试使用不同的隔离加载图像,同时继续执行其他工作并等待隔离工作。

    //start retrieving image here as a future
    getImage(imgUrl).whenComplete((){}).then((value){
    build the image using either CachedNetworkImage or FadeInImage.memeoryNetwork...
    
    });
    
    //call the isolate function
    
    Future getImage(imgUrl) async{
      return compute(downloadImage, imgUrl);
    }
    
    
    downloadImage(imgUrl){
    // get image here
    // return image here
    
    }
    
        3
  •  0
  •   BIS Tech    5 年前

    我找到了自己的方法来解决低性能设备上的崩溃问题。请给我你的反馈

    FadeInImage.memoryNetwork(
        placeholder: kTransparentImage,
        fit: BoxFit.fill,
        imageCacheHeight: 50, //adding these two parameters
        imageCacheWidth: 50,
        image: url,
    )