通過 Windows 命令提示符(cmd)在桌面新建文件夾,并在該文件夾中編譯、運行一段 Java 程序段
1028
2025-04-01
文章目錄
一、Flutter 導入資源圖片
二、Flutter 使用資源圖片
三、完整代碼示例
四、相關資源
一、Flutter 導入資源圖片
Flutter 資源路徑配置 : 資源路徑在根目錄中的 pubspec.yaml 配置文件中配置 ;
將 flutter 節點下的 assets 節點的注釋打開 , 即刪除前面的 # 注釋符號 ;
然后在 flutter 項目根目錄創建 images 目錄 , 將圖片 hunter.png 拷貝到該 images 目錄中 ;
并在 pubspec.yaml 配置文件的 assets 節點下配置 - images/hunter.png 信息 ;
# 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: - images/hunter.png
1
2
3
4
5
6
7
8
9
10
11
之后就可以在 flutter 項目中使用該文件了 ;
下圖展示了資源文件目錄結構以及配置文件中的配置信息 ;
導入資源圖片樣式 :
二、Flutter 使用資源圖片
Image 組件中使用資源圖片 , 在其 image 字段使用 AssetImage 類型的圖片即可 ;
代碼示例 : 設置一個 200 x 200 大小的 Image 組件 , 顯示 images/hunter.png 資源圖片 ;
Image( width: 200, height: 200, image: AssetImage("images/hunter.png"), )
1
2
3
4
5
三、完整代碼示例
完整代碼示例 :
import 'package:flutter/material.dart'; class ResourcePage extends StatefulWidget { @override _ResourcePageState createState() => _ResourcePageState(); } class _ResourcePageState extends State
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
運行效果 :
四、相關資源
參考資料 :
Flutter 官網 : https://flutter.dev/
Flutter 開發文檔 : https://flutter.cn/docs ( 強烈推薦 )
官方 GitHub 地址 : https://github.com/flutter
Flutter 中文社區 : https://flutter.cn/
Flutter 實用教程 : https://flutter.cn/docs/cookbook
Flutter CodeLab : https://codelabs.flutter-io.cn/
Dart 中文文檔 : https://dart.cn/
Dart 開發者官網 : https://api.dart.dev/
Flutter 中文網 ( 非官方 , 翻譯的很好 ) : https://flutterchina.club/ , http://flutter.axuer.com/docs/
Flutter 相關問題 : https://flutterchina.club/faq/ ( 入門階段推薦看一遍 )
博客源碼下載 :
GitHub 地址 : https://github.com/han1202012/flutter_cmd ( 隨博客進度一直更新 , 有可能沒有本博客的源碼 )
博客源碼快照 : https://download.csdn.net/download/han1202012/15539996 ( 本篇博客的源碼快照 , 可以找到本博客的源碼 )
Flutter
版權聲明:本文內容由網絡用戶投稿,版權歸原作者所有,本站不擁有其著作權,亦不承擔相應法律責任。如果您發現本站中有涉嫌抄襲或描述失實的內容,請聯系我們jiasou666@gmail.com 處理,核實后本網站將在24小時內刪除侵權內容。
版權聲明:本文內容由網絡用戶投稿,版權歸原作者所有,本站不擁有其著作權,亦不承擔相應法律責任。如果您發現本站中有涉嫌抄襲或描述失實的內容,請聯系我們jiasou666@gmail.com 處理,核實后本網站將在24小時內刪除侵權內容。