Icon выдает localNotificationsPlugin, как правильно добавить приложение Icon - PullRequest
0 голосов
/ 16 марта 2020

Я реализовал локальные уведомления pu sh в приложении флаттера. Сначала этот плагин работал без сбоев. Проблемы возникли, когда я запустил flutter clean, а также удалил приложение на эмуляторе android, чтобы выполнить чистую установку с flutter run. После этого происходит сбой приложения при запуске.

Когда приложение запускается в режиме отладки, оно показывает, что ошибка происходит на await localNotificationsPlugin.initialize. Отладчик показывает оператор ниже.

Exception has occurred.
PlatformException (PlatformException(INVALID_ICON, The resource ic_launcher could not be found. Please make sure it has been added as a drawable resource to your Android head project., null))

Код ниже показывает, как я реализовал localNotificationsPlugin.

FlutterLocalNotificationsPlugin localNotificationsPlugin =
      FlutterLocalNotificationsPlugin();
  initializeNotifications() async {
    var initAndroid = AndroidInitializationSettings('ic_launcher');
    var initIOS = IOSInitializationSettings();
    var initSettings = InitializationSettings(initAndroid, initIOS);

    await localNotificationsPlugin.initialize(
      initSettings,
      onSelectNotification: gotToNotificationsPage,
    );
  }

  @override
  void initState() {
    super.initState();
    initializeNotifications();
    showNotification();
  }

  Future singleNotification(
      DateTime datetime, String message, String subtext, int hashcode,
      {String sound}) async {
    var androidChannel = AndroidNotificationDetails(
      'channel-id',
      'channel-name',
      'channel-description',
      importance: Importance.Max,
      priority: Priority.Max,
    );

    var iosChannel = IOSNotificationDetails();
    var platformChannel = NotificationDetails(androidChannel, iosChannel);
    localNotificationsPlugin.schedule(
        hashcode, message, subtext, datetime, platformChannel,
        payload: hashcode.toString());
  }

  showNotification() async {
    DateTime now = DateTime.now().toUtc().add(
          Duration(seconds: 5),
        );

    await singleNotification(
      now,
      'Notification',
      'This is a notification',
      98123871,
    );
  }

  Future gotToNotificationsPage(String payload) {
    return Navigator.pushNamed(context, '/notifications');
  }

Примечание проблема в await localNotificationsPlugin.initialize I ' Я не могу правильно назначить значок приложения. Спасибо.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...