How to add image in Flutter

前端 未结 8 1941
渐次进展
渐次进展 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:53

    Create your assets directory the same as lib level

    like this

    projectName
     -android
     -ios
     -lib
     -assets
     -pubspec.yaml
    

    then your pubspec.yaml like

      flutter:
      assets:
        - assets/images/
    

    now you can use Image.asset("/assets/images/")

    0 讨论(0)
  • 2020-12-01 01:57

    I think the error is caused by the redundant ,

    flutter:
      uses-material-design: true, # <<< redundant , at the end of the line
      assets:
        - images/lake.jpg
    

    I'd also suggest to create an assets folder in the directory that contains the pubspec.yaml file and move images there and use

    flutter:
      uses-material-design: true
      assets:
        - assets/images/lake.jpg
    

    The assets directory will get some additional IDE support that you won't have if you put assets somewhere else.

    0 讨论(0)
提交回复
热议问题