How to add image in Flutter

前端 未结 8 1953
渐次进展
渐次进展 2020-12-01 01:10

I am developing Flutter app for the first time.. I have an issue in adding a image. I have a below questions :

  1. Where to create images folder?
  2. Where to
8条回答
  •  情歌与酒
    2020-12-01 01:41

    1. Create images folder in root level of your project.

    2. Drop your image in this folder, it should look like

    3. Go to your pubspec.yaml file, add assets header and pay close attention to all the spaces.

      flutter:
      
        uses-material-design: true
      
        # add this
        assets:
          - images/profile.jpg
      
    4. Tap on Packages get at the top right corner of the IDE.

    5. Now you can use your image anywhere using

      Image.asset("images/profile.jpg")
      

提交回复
热议问题