Flutter - 小尺寸和简单的本地图像加载速度非常慢

问题描述 投票:0回答:1

我有一堆这样的 .jpg 图像(每个都有一个大小 <130 kb) with a width of 800 and height within 500-600 stored in assets/categeory_images in folder which I am trying to load in my app. But it is taking 1-2 seconds for each of the image to load and thus producing the flickering effect which is completely ruining the feel of app

我已经尝试按照接受的答案预缓存图像 非常简单的图像加载速度相当慢与 Flutter ,但它似乎根本没有帮助。以下是我的实现的一部分-

  1. 在main.dart文件中(构建函数)-
Widget build(BuildContext context) {
precacheImage(AssetImage("assets/category_images/motivation.jpg"), context);
precacheImage(AssetImage("assets/category_images/courage.jpg"), context);
//Eliminated many of the precacheImage() statements so as to keep this function short




SystemChrome.setEnabledSystemUIOverlays([]);
  return MultiProvider(
    providers: [
    ListenableProvider<Quotes_DataProvider>(create: (context) => Quotes_DataProvider()),
    ListenableProvider<searchQuote_DataProvider>(create: (context) => searchQuote_DataProvider()),
    ],
    child: MaterialApp(



theme:ThemeData(backgroundColor: Color.fromARGB(255, 234, 234, 234)),
     
        home:WelcomeScreen(),

      routes: {
  
  '/favourites': (context) =>  favouriteScreen(),
  '/quotes': (context) =>  QuoteDisplayScreen(),
  '/categories':(context)=> CategoryScreen(),
  

},
    ),
  );
}
}

还有我的FeaturedQuoteCategory.dart

class _FeaturedQuoteCategoryState extends State<FeaturedQuoteCategory> {

  late final ImageProvider image;
  @override
  void initState() {
  

    super.initState();
    image = AssetImage(widget.imageLocation);
    
  }
  Widget build(BuildContext context) {
 
    return Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        Stack(
          children: [
            ClipRRect(
                borderRadius: BorderRadius.only(topLeft: Radius.circular(10),topRight: Radius.circular(10)),
                child: Image(image:image,
                     
                   
                    fit: BoxFit.cover,
                    width: double.infinity,
                    height: 120,
                    //gaplessPlayback: true,
                  ),
                ),
         
      )
        
         ,
               //backgroundColor: Color.fromARGB(255, 30, 30, 30)
 
          ],

        ),
        
        
       
     
      ],
    );
  }
}

由于我已从上面的代码片段中手动排除了不必要的部分,因此可能缺少冒号/括号。对此表示歉意。

我通过-

显示小部件
FeaturedQuoteCategory(title: "Life Quotes", imageLocation: "assets/category_images/life.jpg",subject: "life",),

基本上我将图像位置作为参数传递给小部件

我尝试过的-

  1. 将每张图像的尺寸缩小至 <130kb
  2. 缩小图像尺寸
  3. 安装此版本的发行版 (
    flutter run --release
    )。肯定会加快速度,但对解决我面临的问题没有帮助
  4. 预缓存(也不起作用)
  5. 哭泣(有助于减轻疼痛,但不能解决问题)

最近两天一直在这个问题上。任何帮助将不胜感激

我的flutter安装配置-

flutter image dart loading image-loading
1个回答
0
投票

你解决这个问题了吗?我目前也有同样的问题

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.