首页 > 解决方案 > Flutter Local Notifications 如何在顶部菜单上显示图标

问题描述

嗨,我的通知工作正常,它也给手机振动,但图标和通知没有显示在屏幕上,你必须向下滑动,你可以在上面的菜单中看到它。我怎样才能在屏幕上显示

应用页面,我想在这里显示小图标 应用页面

手机上的菜单是

上层菜单

FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin;

  @override
  void initState() {
    super.initState();
    _advertService.showBanner();
    flutterLocalNotificationsPlugin = FlutterLocalNotificationsPlugin();
    final android = AndroidInitializationSettings('@mipmap/ic_launcher');
    final iOS = IOSInitializationSettings();
    final initSettings = InitializationSettings(android, iOS);

    flutterLocalNotificationsPlugin.initialize(initSettings,
        onSelectNotification: _onSelectNotification);
  }

  Future<void> _onSelectNotification(String json) async {
    final obj = jsonDecode(json);

    if (obj['isSuccess']) {
      OpenFile.open(obj['filePath']);
    } else {
      showDialog(
        context: context,
        builder: (_) => AlertDialog(
          title: Text('Error'),
          content: Text('${obj['error']}'),
        ),
      );
    }
  }

  Future<void> _showNotification(Map<String, dynamic> downloadStatus) async {
    final android = AndroidNotificationDetails(
        'channel id', 'channel name', 'channel description',
        priority: Priority.High, importance: Importance.Max);
    final iOS = IOSNotificationDetails();
    final platform = NotificationDetails(android, iOS);
    final json = jsonEncode(downloadStatus);
    final isSuccess = downloadStatus['isSuccess'];

    await flutterLocalNotificationsPlugin.show(
        0, // notification id
        isSuccess ? 'Okay' : 'Fail',
        isSuccess
            ? 'Downloaded'
            : 'Failed',
        platform,
        payload: json);
  }

标签: flutter

解决方案


首先,您将设置 Flutter Launcher Icons

  1. 设置配置文件

     dev_dependencies:
     flutter_launcher_icons: "^0.7.3"
    
     flutter_icons:
     android: "launcher_icon"
     ios: true
     image_path: "assets/icon/icon.png"
    

如果您将配置文件命名为 flutter_launcher_icons.yaml 或 pubspec.yaml 以外的名称,则需要在运行包时指定文件名。

注意:如果您不使用现有的 pubspec.yaml,请确保您的配置文件位于与其相同的目录中。

  1. 运行包

      flutter pub get
      flutter pub run flutter_launcher_icons:main
    

使用这个插件


推荐阅读