【问题标题】:'MissingPluginException' is not a subtype of type 'String' error in flutter local notification“MissingPluginException”不是颤振本地通知中“字符串”类型错误的子类型
【发布时间】:2019-04-16 07:25:19
【问题描述】:

我尝试了以下代码。它给出的“MissingPluginException”不是“String”类型的子类型 下面是我使用的代码(此处仅粘贴通知部分)。颤振医生也没有问题。

import 'package:flutter_local_notifications/flutter_local_notifications.dart';

class _Home extends State<HomePage> with TickerProviderStateMixin {
     static FirebaseMessaging _firebaseMessaging = FirebaseMessaging();
     FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin = new FlutterLocalNotificationsPlugin();

@override
  void initState() {
    super.initState();
    firebaseCloudMessaging_Listeners();

  }
void firebaseCloudMessaging_Listeners() {
    var android = new AndroidInitializationSettings('mipmap/ic_launcher',);
    var ios = new IOSInitializationSettings();
    var platform = new InitializationSettings(android, ios);

    flutterLocalNotificationsPlugin.initialize(platform,onSelectNotification: onSelectNotification);

    if (Platform.isIOS) iOS_Permission();
    _firebaseMessaging.getToken().then((token){
      //FCM=token;
    }).catchError((onError){
      print("blb07 "+onError.toString());
    });

    _firebaseMessaging.configure(
      onMessage: (Map<String, dynamic> message) async {
        print('blb07 on message $message');
        handleNotification(message['data']['message']);
      },
      onResume: (Map<String, dynamic> message) async {
        print('blb07 on resume $message');
        handleNotification(message['data']['message']);
      },
      onLaunch: (Map<String, dynamic> message) async {
        print('blb07 on launch $message');
        handleNotification(message['data']['message']);
      },
    );
  }

  void iOS_Permission() {
    _firebaseMessaging.requestNotificationPermissions(
        IosNotificationSettings(sound: true, badge: true, alert: true)
    );
    _firebaseMessaging.onIosSettingsRegistered
        .listen((IosNotificationSettings settings)
    {
      print("Settings registered: $settings");
    });
  }
  Future onSelectNotification(String payload) async {
    await Navigator.push(
      context,
      new MaterialPageRoute(builder: (context) => new DisplayNotifications()),
    );
  }

  void handleNotification(String message) async{
      var androidPlatformChannelSpecifics = new AndroidNotificationDetails(
          'default1', 'Sureworks ', 'Sureworks app notifications',
          importance: Importance.Max, priority: Priority.High);
      var iOSPlatformChannelSpecifics = new IOSNotificationDetails();
      var platformChannelSpecifics = new NotificationDetails(
          androidPlatformChannelSpecifics, iOSPlatformChannelSpecifics);
      print("blb07 start");
      try{
        await flutterLocalNotificationsPlugin.show(0, 'Sureworks', message, platformChannelSpecifics,payload: 'item')
            .then((onValue){
          print("blb07 finished");
        }).catchError((onError)=>print("blb07 "+onError));
        print("blb07 hello end line");
      }catch(e){
        print("blb07 error "+e.toString());
      }
  }
} 

我的 pubspec.yaml 依赖项

dev_dependencies:
  flutter_test:
    sdk: flutter

  http: ^0.11.3+16
  shared_preferences: ^0.4.2
  firebase_messaging: ^4.0.0+1
  firebase_core: ^0.2.5
  flutter_launcher_icons: ^0.7.0
  paging: ^0.1.0
  flutter_local_notifications: ^0.6.1

可能是什么问题?传递给 handleNotification 函数的消息仅是字符串格式。从服务器接收通知数据没有问题。

【问题讨论】:

    标签: flutter localnotification


    【解决方案1】:

    你运行pod install 了吗? 如果不是,则很可能在本机方面缺少某些东西。

    只需打开一个终端并导航到您的 Flutter 项目根目录。
    然后cd进入iOS文件夹并运行pod install

    这应该可以解决您的错误。

    【讨论】:

    • 不,没有运行该命令。现在我在 IOS 文件夹的终端中完成了它。它给出了一个错误“pod”命令未找到。我正在使用 ubuntu 操作系统。
    • 啊,好吧。这似乎是你为 iOS 开发的。那么 Pod 就不是问题了。
    【解决方案2】:

    我找到了解决方案。将我的 Android 迁移到 AndroidX。现在它工作正常。在上面花了4个多小时。 迁移到 AndroidX 并“使缓存无效并重新启动”就成功了。

    【讨论】:

      猜你喜欢
      • 2021-08-09
      • 2021-08-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-08-23
      • 2020-10-28
      • 2022-01-25
      相关资源
      最近更新 更多