简体   繁体   中英

flutter - Image Widget how to show multi network images at the same time?

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?

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

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');

}

);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM