我有一堆这样的 .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 ,但它似乎根本没有帮助。以下是我的实现的一部分-
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",),
基本上我将图像位置作为参数传递给小部件
我尝试过的-
flutter run --release
)。肯定会加快速度,但对解决我面临的问题没有帮助最近两天一直在这个问题上。任何帮助将不胜感激
你解决这个问题了吗?我目前也有同样的问题