小编Tos*_*003的帖子

为什么 flutter 本地通知会出现异常

我正在尝试使用以下依赖项在 android 上发送颤振通知:

“flutter_local_notifications:^9.0.1”

但当我单击“测试”按钮时,它给了我这个错误。

任何人都知道我该如何解决它?

/////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////

在main.dart中:

 ElevatedButton(
      onPressed: () => NotificationApi.showNotification(
          title: 'Samira', body: 'Heyy theree !!!', payload: 'samira'),
      child: Text("test"),

Run Code Online (Sandbox Code Playgroud)

在notification.dart中:

import 'package:flutter_local_notifications/flutter_local_notifications.dart';

class NotificationApi {
  static final _notifications = FlutterLocalNotificationsPlugin();

  static Future _notificationDetails() async {
    return const NotificationDetails(
      android: AndroidNotificationDetails(
        'channel id',
        'channel name',
        channelDescription: 'channel description',
        importance: Importance.max,
      ),
      //iOS: IOSNotificationDetails(),
    );
  }

  static Future showNotification({
    int id = 0,
    String? title,
    String? body,
    String? payload,
  }) async =>
      _notifications.show(
        id,
        title,
        body,
        await …
Run Code Online (Sandbox Code Playgroud)

flutter flutter-notification flutter-local-notification

1
推荐指数
1
解决办法
2398
查看次数