簡體   English   中英

我遇到了 flutter_local_notifications 的問題。 我該如何解決這個問題?

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM