flutter image加载本地图片

  • 项目中创建assets文件夹,图片拖放到文件夹中。
  • pubspect.yaml文件中,添加图片路径:
# The following section is specific to Flutter.
flutter:

  # The following line ensures that the Material Icons font is
  # included with your application, so that you can use the icons in
  # the material Icons class.
  uses-material-design: true

  # To add assets to your application, add an assets section, like this:
  assets:
     - assets/1.png
     - assets/2.png

注意: assets:前不要有空格,否则报错。

  • 引用本地图片:
new Image.asset('assets/1.png'),
new Image.asset('assets/2.png'),

猜你喜欢

转载自blog.csdn.net/weixin_33720956/article/details/86785066