原文
https://medium.com/@bharadwaj.palakurthy/the-easiest-way-to-make-app-icons-in-flutter-9fe1bc9dd646
參考
正文
讓我們承認(rèn)這一點(diǎn)ーー管理應(yīng)用程序圖標(biāo)是一項(xiàng)重復(fù)的任務(wù)嘴纺。他們必須生成的多分辨率和手動(dòng)放置在幾個(gè)文件夾真仲,這是一個(gè)世俗的任務(wù)采取隔心。你可能需要做一些小的改變或者修改蛉加,現(xiàn)在你必須重復(fù)整個(gè)替換圖標(biāo)的過程。
不僅如此值戳,根據(jù)我們選擇的平臺(tái)或操作系統(tǒng)的版本对竣,還應(yīng)用了不同的規(guī)則巫玻。所以把這些都記在心里,這個(gè)過程最好是自動(dòng)化逗栽,而不是手動(dòng)完成盖袭。我們將在這里使用這個(gè)名為“ flutter_launcher_icons”的 flutter 包來自動(dòng)生成所有需要的分辨率。
Flutter Launcher Icons:
一個(gè)命令行工具彼宠,簡化了更新應(yīng)用程序啟動(dòng)圖標(biāo)的任務(wù)鳄虱。完全靈活,允許你選擇你想要更新啟動(dòng)器圖標(biāo)的平臺(tái)凭峡,如果你想要的話拙已,選擇保留你的舊啟動(dòng)器圖標(biāo),以防你想在未來的某個(gè)時(shí)候返回摧冀。
先決條件
在任何情況下倍踪,當(dāng)從圖形編輯器導(dǎo)出時(shí),應(yīng)該是:
- Format: 32-bit 格式: 32 位PNG 巴布亞新幾內(nèi)亞
- Icon size 圖標(biāo)大小must be up to 1024x1024 pixels 必須達(dá)到 1024x1024 像素
- 確保在 40 像素處可見(這是最小的圖標(biāo))(Apple Requirement) (蘋果需求)
- 最大尺寸1024KB (Android Requirement) 1024KB (Android 版本要求)
- 圖標(biāo)必須用no transparency 沒有透明度
- 形狀必須是正方形no rounded corners 沒有圓角
- 需要一個(gè)自適應(yīng)的 android 圖標(biāo)background 背景and 及foreground 前景to be separated 分開
安卓產(chǎn)品圖標(biāo)關(guān)鍵字
The intended look might be different from the guidelines provided by the platforms. So we’ll be creating 3 different flavors for android, iOS, adaptive icons.
預(yù)期的外觀可能與平臺(tái)提供的指導(dǎo)方針不同索昂。因此建车,我們將為 android、 iOS 和自適應(yīng)圖標(biāo)創(chuàng)建三種不同的風(fēng)格椒惨。
預(yù)期外觀
Android and iOS (no transparency) 安卓和 iOS (沒有透明度)
Adaptive Icons for Android 8.0 and above 8.0 及以上版本的自適應(yīng)圖標(biāo)
實(shí)施方案:
我們將使用一個(gè)名為 flutter_launcher_icons 的包
現(xiàn)在我們需要分別在你的代碼中實(shí)現(xiàn)它:
- 第一步: 添加依賴項(xiàng)缤至。
將 dependency 添加到位于 Flutter 項(xiàng)目根目錄中的 pubspec.yaml 文件:
dev_dependencies:
flutter_launcher_icons: any
- 第二步: 配置屬性
flutter_icons:
ios: true
android: true
image_path_ios: "assets/launcher/icon.png"
image_path_android: "assets/launcher/icon.png"
adaptive_icon_background: "assets/launcher/background.png"
adaptive_icon_foreground: "assets/launcher/foreground.png"
圖像在你的 assets/launcher/
- 第三步: 運(yùn)行包
設(shè)置完配置后,剩下要做的就是運(yùn)行包康谆。
flutter pub get
flutter pub run flutter_launcher_icons:main
- 第四步: 跑步
如果一切順利领斥,資產(chǎn)已經(jīng)產(chǎn)生〖档剑現(xiàn)在,您已經(jīng)準(zhǔn)備好構(gòu)建應(yīng)用程序并運(yùn)行它了戒突。恭喜你
屬性:
目前屯碴,它只能用于為 android/ios 分配圖標(biāo)
- image_path 圖像路徑: : 圖標(biāo)圖像文件的位置,你想用它作為應(yīng)用程序啟動(dòng)圖標(biāo)
- image_path_android 圖片/path/android: : 特定于 Android 平臺(tái)的圖標(biāo)圖像文件的位置
- image_path_ios 圖片/path/ios: : 特定于 iOS 平臺(tái)的圖標(biāo)圖像文件位置
接下來的兩個(gè)屬性只在生成 Android 啟動(dòng)器圖標(biāo)時(shí)使用
- adaptive_icon_background 背景: You can pass in a solid color (E.g. “#ffffff”) or image asset (E.g. “assets/images/christmas-background.png”) which will be used to fill out the background of the adaptive icon.
- adaptive_icon_foreground 自適應(yīng)圖標(biāo)前景: The image asset which will be used for the icon foreground of the adaptive icon : 將用于自適應(yīng)圖標(biāo)的前景圖標(biāo)的圖像資產(chǎn)
Thank you!
謝謝
? 貓哥
微信群 ducafecat
往期
開源
GetX Quick Start
https://github.com/ducafecat/getx_quick_start
新聞客戶端
https://github.com/ducafecat/flutter_learn_news
strapi 手冊譯文
微信討論群 ducafecat
系列集合
譯文
https://ducafecat.tech/categories/%E8%AF%91%E6%96%87/
開源項(xiàng)目
https://ducafecat.tech/categories/%E5%BC%80%E6%BA%90/
Dart 編程語言基礎(chǔ)
https://space.bilibili.com/404904528/channel/detail?cid=111585
Flutter 零基礎(chǔ)入門
https://space.bilibili.com/404904528/channel/detail?cid=123470
Flutter 實(shí)戰(zhàn)從零開始 新聞客戶端
https://space.bilibili.com/404904528/channel/detail?cid=106755
Flutter 組件開發(fā)
https://space.bilibili.com/404904528/channel/detail?cid=144262
Flutter Bloc
https://space.bilibili.com/404904528/channel/detail?cid=177519
Flutter Getx4
https://space.bilibili.com/404904528/channel/detail?cid=177514
Docker Yapi
https://space.bilibili.com/404904528/channel/detail?cid=130578