显示通知的最简单方法

时间:2020-03-30 05:02:01

标签: flutter dart android-notifications

有什么简单的方法可以在Flutter中显示通知吗?我已经尝试使用this plugin

final FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin =
FlutterLocalNotificationsPlugin();
NotificationAppLaunchDetails notificationAppLaunchDetails;

Future<void> _showNotification(String msg) async {
    var androidPlatformChannelSpecifics = AndroidNotificationDetails(
        '696969', 'FCPN', 'FCPN Example',
        importance: Importance.Max, priority: Priority.High, ticker: 'ticker');
    var iOSPlatformChannelSpecifics = IOSNotificationDetails();
    var platformChannelSpecifics = NotificationDetails(
        androidPlatformChannelSpecifics, iOSPlatformChannelSpecifics);
    await flutterLocalNotificationsPlugin.show(
        0, 'plain title', msg, platformChannelSpecifics,
        payload: 'item x');
}

但是我有空指针

1 个答案:

答案 0 :(得分:0)

对于iOS,您必须配置Xcode文件。

将以下行添加到iOS项目的didFinishLaunchingWithOptions文件中的AppDelegate.m/AppDelegate.swift方法中

pub.dev上查看flutter_local_notifications的自述文件以获取更多信息。

相关问题