Home > Software engineering >  Flutter show image with network url directly form Firestore is very slow
Flutter show image with network url directly form Firestore is very slow

Time:04-22

I am storing Firestore image url in my db and fetch directly form flutter app. It is very slow even compare with image hosting on DO's 6$ per month server. It took me nearly one minute to show the images. Is there anyway to improve the speed?

https://firebasestorage.googleapis.com/v0/b/myproject.appspot.com/o/images/albums/chin thae lae pyan.jpg?alt=media&token=9966803a-d4a7-4686-a0c2-8f5367bc89f6

Container(
                  decoration: BoxDecoration(
                    image: DecorationImage(
                      image: NetworkImage(album.albumCover),
                      fit: BoxFit.cover,
                    ),
                  ),
                  child: Align(
                    alignment: Alignment.bottomRight,
                    child: Container(
                      margin: const EdgeInsets.all(5),
                      //padding: const EdgeInsets.all(5),
                      decoration: BoxDecoration(
                          color: Theme.of(context).primaryColor,
                          borderRadius: BorderRadius.circular(100)),
                      child: const Icon(
                        Icons.play_arrow,
                        color: Colors.white,
                      ),
                    ),
                  ),
                )

CodePudding user response:

Hello you need can use CachedNetworkImage instead of NetworkImage refer below

CachedNetworkImage

CachedNetworkImage(
      imageUrl: "your_image_url",
      imageBuilder: (context, imageProvider) => Container(
        decoration: BoxDecoration(
          image: DecorationImage(
              image: imageProvider,
              fit: BoxFit.cover,
          ),
        ),
      ),
      placeholder: (context, url) => CircularProgressIndicator(),
      errorWidget: (context, url, error) => Icon(Icons.error),
    ),

let me know if you have any query

  • Related