On my widget,
I have 3 Image Widgets to load 3 image's url.
As we all know, 3 Image Widgets load images has time difference ,
But I have a requirement:
After 3 images all downloaded, then 3 Image Widgets show these 3 images at the same time,
how to do?
CodePudding user response:
Image.network(
widget.networkUrl,
fit: BoxFit.fill,
loadingBuilder: (BuildContext context, Widget child,
ImageChunkEvent? loadingProgress) {
if (loadingProgress == null) return child;
return Center(
child: CircularProgressIndicator(
value: loadingProgress.expectedTotalBytes != null
? loadingProgress.cumulativeBytesLoaded /
loadingProgress.expectedTotalBytes!
: null,
),
);
},
),
try to this
CodePudding user response:
Use precache with FutureBuilder as below.
FutureBuilder(
future: Future.wait([
precacheImage(NetworkImage('url_1'), context),
precacheImage(NetworkImage('url_2'), context),
//... More futures
]),
builder: (
context,
// List of booleans(results of all futures above)
AsyncSnapshot<List<bool>> snapshot,
){
if (!snapshot.hasData) {
return CircularProgressIndicator();
}
return Image.network('url_1');
}
);
