[英]I'm having Issues with flutter_local_notifications. How do i fix this problem?
我已經嘗試了下面的代碼,看來我還需要做一些事情。 我正在使用flutter_local_notification。 我需要包括 firebase。 這是我的代碼
import 'package:flutter/material.dart';
import 'package:flutter_local_notifications/flutter_local_notifications.dart';
class NotificationApi {
static final _notifications = FlutterLocalNotificationsPlugin();
static Future _notificationDetails() async {
return NotificationDetails(
android: AndroidNotificationDetails(
'com.example.gym',
'goal_channel',
importance: Importance.max,
),
iOS: IOSNotificationDetails(),
);
}
static Future showNotification({
int id = 0,
String? title,
body,
payload,
}) async =>
_notifications.show(
id,
title,
body,
await _notificationDetails(),
payload: payload,
);
}
感謝@Amroun
這是一個工作代碼
import 'package:flutter/material.dart';
import'package:flutter_local_notifications/flutter_local_notifications.dart';
class NotificationApi {
static final _notifications = FlutterLocalNotificationsPlugin();
static Future _notificationDetails() async {
return NotificationDetails(
android: AndroidNotificationDetails(
'com.example.gym',
'goal_channel',
icon: '@mipmap/ic_launcher',
importance: Importance.max,
),
iOS: IOSNotificationDetails(),
);
}
static Future showNotification({
int id = 0,
String? title,
body,
payload,
}) async =>
_notifications.show(
id,
title,
body,
await _notificationDetails(),
payload: payload,
);
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.