我使用
flutter_launcher_icons
包在 flutter 应用程序中设置默认应用程序图标(特别适用于 Android)。
现在,我必须使用 svg
文件作为图标,因为 png
图标在通知栏中的深色主题 Android 版本中无法正确显示。
但它显示了一些NoDecoderForImageFormatException
的错误。
pubspec.yaml 文件配置:
flutter_icons:
# image_path: "assets/images/icon-128x128.png"
android: "launcher_icon"
ios: true
image_path: "assets/images/logo.svg"
这是
flutter pub run flutter_launcher_icons:main
命令的输出。
pub run flutter_launcher_icons:main
════════════════════════════════════════════
FLUTTER LAUNCHER ICONS (v0.9.0)
════════════════════════════════════════════
• Creating default icons Android
✓ Successfully generated launcher icons
Unhandled exception:
✗ ERROR: NoDecoderForImageFormatException
assets/images/logo.svg
#0 decodeImageFile (package:flutter_launcher_icons/utils.dart:37:5)
#1 createDefaultIcons (package:flutter_launcher_icons/android.dart:35:24)
#2 createIconsFromConfig (package:flutter_launcher_icons/main.dart:103:5)
#3 createIconsFromArguments (package:flutter_launcher_icons/main.dart:60:7)
#4 main (file:///home/jspw/Android/Sdk/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_launcher_icons-0.9.0/bin/main.dart:6:3)
#5 _delayEntrypointInvocation.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:281:32)
#6 _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:184:12)
pub finished with exit code 255
包flutter_launcher_icons仅使用PNG图像来创建所有不同尺寸的徽标(hdpi、mdpi、xhdpi等...)
如果您在使用 Android 时遇到问题,您是否尝试过使用
adaptive_icon_background
和 adaptive_icon_foreground
属性?
确保使用
adaptive_icon_background
和 adaptive_icon_foreground
,如下所示:
dev_dependencies:
...
flutter_launcher_icons: "^0.14.2"
flutter_launcher_icons:
android: true //just replace the existing one
ios: true
image_path: "images/launcher_icon.png" //must match the file name!!!
adaptive_icon_background: "#ffffff"
adaptive_icon_foreground: "images/launcher_icon.png" //must match the file name!!!
min_sdk_android: 21
web:
generate: true
windows:
generate: true
macos:
generate: true