当我使用flutter create命令创建应用程序时,flutter标志将用作两个平台的应用程序图标。
如果我想改变应用程序的图标,我是否应该去两个平台的目录并替换那里的图像?我说的平台目录是myapp/ios/Runner/Assets.xcassets/AppIcon。apppiconset用于iOS, myapp/android/app/src/main/res用于android。
或者可以将图像定义为颤振资产和图标以某种方式生成?
当我使用flutter create命令创建应用程序时,flutter标志将用作两个平台的应用程序图标。
如果我想改变应用程序的图标,我是否应该去两个平台的目录并替换那里的图像?我说的平台目录是myapp/ios/Runner/Assets.xcassets/AppIcon。apppiconset用于iOS, myapp/android/app/src/main/res用于android。
或者可以将图像定义为颤振资产和图标以某种方式生成?
当前回答
您必须将Flutter图标文件替换为您自己的图像。这个网站将帮助你把你的png转换成各种大小的启动器图标:
https://romannurik.github.io/AndroidAssetStudio/icons-launcher.html
其他回答
上面许多答案中推荐的flutter_launcher_icons包现在已经有一段时间没有更新了,并且正在抛出一个未捕获的异常。
你也可以使用icons_launcher包。
更新pubspec.yaml
dev_dependencies:
icons_launcher: ^1.1.7
flutter_icons:
image_path: 'assets/ic_logo_border.png'
ios: true
android: true
运行包
flutter pub get
flutter pub run icons_launcher:main
flutter_launcher_icons: ^ 0.11.0
将此添加到你的pubspec中。yaml文件
dev_dependencies:
flutter_launcher_icons: "^0.11.0"
flutter_icons:
android: "launcher_icon"
ios: true
image_path: "assets/icon/icon.png"
min_sdk_android: 21 # android min sdk min:16, default 21
# optionally, as transparency is not allowed on app store
# remove_alpha_ios: true
添加后,运行以下命令
$颤振酒吧得到
$ flutter pub运行flutter_launcher_icons:main
在Flutter中设置应用程序图标的最佳推荐方法。
我找到了一个插件来设置应用程序图标在flutter名为flutter_launcher_icons。我们可以使用这个插件在flutter中设置应用程序图标。
在pubspec中添加此插件。项目根目录下的Yaml文件。请检查以下代码,
dependencies:
flutter:
sdk: flutter
cupertino_icons: ^0.1.2
flutter_launcher_icons: ^0.7.2+1**
保存文件并在终端上运行flutter pub get。
在项目的根文件夹资产中创建一个文件夹资产,同时创建一个文件夹图标,并将应用程序图标放在这个文件夹中。我将推荐给用户1024x1024的应用程序图标大小。我已经把应用程序图标放在图标文件夹内,现在我有应用程序图标路径为assets/icon/icon.png 现在,在pubspec中。Yaml添加下面的代码,
flutter_icons:
android: "launcher_icon"
ios: true
image_path: "assets/icon/icon.png"
保存文件并在终端上运行flutter pub get。运行命令后,运行第二条命令,如下所示
flutter pub run flutter_launcher_icons:main -f pubspec.yaml
然后运行App
遵循以下步骤:-
1. 在pubspec中添加flutter_luncher_icons的依赖项。yaml文件。你可以在这里找到这个插件。
2. 在资产文件夹和pubspec中添加所需的图像。Yaml文件如下。
pubspec.yaml
name: NewsApi.org
description: A new Flutter application.
# The following line prevents the package from being accidentally published to
# pub.dev using `pub publish`. This is preferred for private packages.
publish_to: 'none' # Remove this line if you wish to publish to pub.dev
https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
version: 1.0.0+1
environment:
sdk: ">=2.7.0 <3.0.0"
dependencies:
flutter:
sdk: flutter
# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^1.0.1
fluttertoast: ^7.1.6
toast: ^0.1.5
flutter_launcher_icons: ^0.8.0
dev_dependencies:
flutter_test:
sdk: flutter
flutter_icons:
image_path: "assets/icon/newsicon.png"
android: true
ios: false
# 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
assets:
- assets/images/dropbox.png
fonts:
- family: LangerReguler
fonts:
- asset: assets/langer_reguler.ttf
# fonts:
# - family: Schyler
# fonts:
# - asset: fonts/Schyler-Regular.ttf
# - asset: fonts/Schyler-Italic.ttf
# style: italic
# - family: Trajan Pro
# fonts:
# - asset: fonts/TrajanPro.ttf
# - asset: fonts/TrajanPro_Bold.ttf
# weight: 700
#
# For details regarding fonts from package dependencies,
# see https://flutter.dev/custom-fonts/#from-packages
3.执行terminal flutter pub get命令,然后执行flutter_luncher_icon命令。这是成功运行命令后得到的结果。并成功生成了午餐图标。
我的终端
[E:\AndroidStudioProjects\FlutterProject\NewsFlutter\news_flutter>flutter pub get
Running "flutter pub get" in news_flutter... 881ms
E:\AndroidStudioProjects\FlutterProject\NewsFlutter\news_flutter>flutter pub run flutter_launcher_icons:main
════════════════════════════════════════════
FLUTTER LAUNCHER ICONS (v0.8.0)
════════════════════════════════════════════
• Creating default icons Android
• Overwriting the default Android launcher icon with a new icon
✓ Successfully generated launcher icons
我使用很少的方法来更换颤振应用程序lancher图标,但只有手动方法是有点容易和好。因为你会知道它是如何运作的。
更改flutter ios图标。首先得到你的图标1024×1024像素的副本,并生成一组图标的android和ios使用appicon。有限公司发电机。 当你得到压缩文件,它工作创建两个文件夹ios和android打开ios文件夹和复制文件夹,并替换一个在你的ios/runner目录。
对于android,复制android文件夹中的所有文件夹,并替换在android/app/src/main/res/drawable中的文件夹。
在ios和android上替换文件夹后,停止应用程序并重新运行,您的图标将被更改。