小编Ebr*_*man的帖子

如何在“flutter_background_fetch”中实现“flutter_local_notifications”插件以在 Flutter 中在没有 FIREBASE 的情况下在线推送通知

我想在触发后台进程时启动通知,我尝试在 BackgroundFetch 方法中调用通知类,但没有用,但是当我打印调试消息时,它可以工作。

我想让这个功能与应用程序的业务逻辑隔离,这是我的尝试

1-通知类:

class LocalNotificationWidget extends StatefulWidget {

  @override
  _LocalNotificationWidgetState createState() =>
      _LocalNotificationWidgetState();
}

class _LocalNotificationWidgetState extends State<LocalNotificationWidget> {
  final notifications = FlutterLocalNotificationsPlugin();

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

    final settingsAndroid = AndroidInitializationSettings('app_icon');

    final settingsIOS = IOSInitializationSettings(
        onDidReceiveLocalNotification: (id, title, body, payload) =>
            onSelectNotification(payload));

    notifications.initialize(
        InitializationSettings(settingsAndroid, settingsIOS),
        onSelectNotification: onSelectNotification);

    showOngoingNotification(notifications,
        title: 'Tite', body: 'hello');
  }

  Future onSelectNotification(String payload) async => await Navigator.push(
        context,
        MaterialPageRoute(builder: (context) => SecondScreen( payload)),
      );

  @override
  Widget build(BuildContext context) => Container();

  Widget title(String text) => …
Run Code Online (Sandbox Code Playgroud)

push-notification flutter

5
推荐指数
0
解决办法
952
查看次数

标签 统计

flutter ×1

push-notification ×1