使用Flutter推荐的应用程序图标
Flutter中推荐使用应用程序图标来设置通知的图标。为此,您可以使用Flutter的flutter_launcher_icons插件来将应用程序的图标生成为各种大小和格式,以便在通知中使用。
在pubspec.yaml文件中,添加flutter_launcher_icons插件:
dev_dependencies:
flutter_launcher_icons: "^0.9.0"
flutter_icons:
android: true
ios: true
image_path: "assets/icon/icon.png"
然后运行以下命令生成图标:
flutter pub get
flutter pub run flutter_launcher_icons:main
最后,在flutter_local_notifications中设置图标:
var androidPlatformChannelSpecifics = AndroidNotificationDetails(
'channel Id', 'channel name', 'channel description',
importance: Importance.Max, priority: Priority.High, ticker: 'test', icon: 'app_icon');
将icon参数设置为"app_icon",它将映射到Android和iOS的应用程序图标。