How to Show an Local image till the NetworkImage() Loads Up in flutter?

前端 未结 9 1132
忘掉有多难
忘掉有多难 2021-02-13 03:15
            new CircleAvatar(
                              backgroundColor: Colors.black87,
                              backgroundImage: new NetworkImage(url),
               


        
9条回答
  •  天命终不由人
    2021-02-13 03:56

    Two way to solve your problem

    1) Using Image.network : If you want to show progressbar,simmer or any other widget when image loading.

      Image.network(
          "URL",
          fit: BoxFit.cover,
          loadingBuilder: (BuildContext ctx, Widget child, ImageChunkEvent loadingProgress) {
            if (loadingProgress == null) {
              return child;
            }else {
              return Center(
                child: CircularProgressIndicator(
                  valueColor: AlwaysStoppedAnimation(Colors.green),
                ),
              );
            }
          },       
      )
    



    2) Using FadeInImage : If you want to display your local image when network image loading

     FadeInImage.assetNetwork( 
        image:"URL",
        placeholder:"assets/loading.png" // your assets image path
        fit: BoxFit.cover,
      )
    

提交回复
热议问题