首页 > 解决方案 > 如何使用 Flutter_bloc 显示通知

问题描述

我是 flutter_bloc 包的新手。如何使用 flutter_bloc 包显示通知警报。这是我在不使用 bloc 的情况下所做的示例。

                  IconButton(
                    icon: Icon(Icons.notifications),
                    onPressed: () {
                      String time=7:30
                      List<String> arr = time.split(':');
                      int aa = int.parse(arr[0]);
                      int bb = int.parse(arr[1]);
                      var time = new Time(aa, bb, 0);
                      var android = new AndroidNotificationDetails(
                        'Channel Id', 'Channel Name', 'Channel Des',);
                      var iOS = new IOSNotificationDetails();
                      var platform = new NotificationDetails(android, iOS);
                      flutterLocalNotificationsPlugin.showDailyAtTime(0, 'show daily title',
                          'Daily notification shown at approximately', time, platform);
                    },
                  )

标签: flutterdartblocflutter-bloc

解决方案


如果你想在IconButton点击时显示一些通知,你可以使用 BlocListener :

  1. 首先,进行business logic集体通知
  2. 使用BlocProvider
  3. BlocListener在应用程序中使用 Bloc 并根据 Bloc 状态显示收听 Bloc

推荐阅读