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

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


        
9条回答
  •  一生所求
    2021-02-13 03:36

    There is a new official widget for this now!

    First, create a folder called assets in the project root directory.

    Then, mention the folder in pubspec.yaml file (also found in the project root directory):

    flutter:
      uses-material-design: true
      assets:
        - assets/
    

    You can put a picture there, for example, put this as ./assets/loading.gif.

    (If you changed files in assets folder, hot reload won't work. Make sure you restart the app entirely.)

    Now you can refer to the loading file in the code:

    FadeInImage.assetNetwork(
      placeholder: 'assets/loading.gif',
      image: 'https://github.com/flutter/website/blob/master/src/_includes/code/layout/lakes/images/lake.jpg?raw=true',
    );
    

    For more details: https://flutter.io/docs/cookbook/images/fading-in-images#from-asset-bundle

提交回复
热议问题