Flutter 應(yīng)用程序包含代碼和 assets(也為資源)。資源是被打包到應(yīng)用程序安裝包中,可以在運行時訪問的一種文件。常見的資源類型包括靜態(tài)數(shù)據(jù)(例如 JSON 文件),配置文件,圖標(biāo)和圖片(JPEG,WebP,GIF,動畫 WebP / GIF,PNG,BMP 和 WBMP)。
加載本地圖片
新建資源文件夾assets,將圖片加入到文件夾中

新建資源文件夾.png
聲明分辨率相關(guān)的圖片assets

官方文檔.png
大坑提示:若想Android Studio自動識別分辨率相關(guān)圖片,必須給定1.0x圖片,否則,需指定具體路徑,如:assets/public/3.0x/xxx.png。
插件推薦:flutter_add_image,可自動通過3x圖片生成1x,2x圖片。
在pubspec.yaml新增相關(guān)路徑
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/public/
- assets/public/2.0x/
- assets/public/3.0x/
代碼調(diào)用
Image.asset('assets/public/xxx.png')