awesome_notifications icon indicating copy to clipboard operation
awesome_notifications copied to clipboard

Why actionbutton dismiss all the notification in same group?

Open whquddn55 opened this issue 2 years ago • 0 comments

I'm trying to put a cancel button on the progress notification. To distinguish progress notifications from other general notifications, I divided them into groups, and confirmed that the grouping works well. The code is below.

However, after grouping like this, when the ActionButton is pressed, not only one notification is dismissed, but all notifications in the group are dismissed.

Just in case, I set the autoDissmissible option of NotificationActionButton to false and tried to use the cancel or dismiss function, but all of them are dismissed as well.

Any solution?

https://user-images.githubusercontent.com/26822105/158821700-87c66fca-833e-4b9a-970d-4eefd4fa6874.mp4

  await AwesomeNotifications().initialize(null, [
    NotificationChannel(
      groupKey: 'ppab_noti_download_progress',
      channelGroupKey: 'ppab_noti_download_progress',
      channelKey: 'ppab_noti_download_progress',
      channelName: '플라토 브라우저 다운로드 진행 상태',
      channelDescription: '플라토 브라우저 다운로드 진행 상태를 보여줌',
      onlyAlertOnce: true,
      enableLights: false,
      playSound: false,
      enableVibration: false,
      locked: true,
      channelShowBadge: false,
    ),
    NotificationChannel(
      groupKey: 'ppab_noti_download_result',
      channelGroupKey: 'ppab_noti_download_result',
      channelKey: 'ppab_noti_download_result',
      channelName: '플라토 브라우저 다운로드 결과',
      channelDescription: '플라토 브라우저 다운로드 결과를 보여줌',
      enableLights: true,
      playSound: true,
      enableVibration: true,
      channelShowBadge: true,
      defaultPrivacy: NotificationPrivacy.Public,
      importance: NotificationImportance.Max,
    ),
    NotificationChannel(
      groupKey: 'ppab_noti_normal',
      channelGroupKey: 'ppab_noti_normal',
      channelKey: 'ppab_noti_normal',
      channelName: '플라토 브라우저 일반 알림',
      channelDescription: '플라토 브라우저 알림을 보여줌',
      enableLights: true,
      playSound: true,
      enableVibration: true,
      channelShowBadge: true,
      defaultPrivacy: NotificationPrivacy.Public,
      importance: NotificationImportance.Max,
    ),
  ], channelGroups: [
    NotificationChannelGroup(channelGroupkey: 'ppab_noti_download_progress', channelGroupName: 'download progress'),
    NotificationChannelGroup(channelGroupkey: 'ppab_noti_download_result', channelGroupName: 'download result'),
    NotificationChannelGroup(channelGroupkey: 'ppab_noti_normal', channelGroupName: 'normal'),
  ]);

  AwesomeNotifications().actionStream.listen((ReceivedAction receivedAction) {
    if (receivedAction.buttonKeyPressed == "cancel") {
      print(receivedAction.toMap().toString());
    }
  });

  runApp(MaterialApp(builder: (context, child) => const HomeScreen()));
}

class HomeScreen extends StatefulWidget {
  const HomeScreen({Key? key}) : super(key: key);

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

class _HomeScreenState extends State<HomeScreen> {
  int count = 0;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text("Application Life Cycle")),
      body: Column(
        children: [
          Center(
            child: Text('$count'),
          ),
          ElevatedButton(
              child: const Text("show group 1"),
              onPressed: () async {
                setState(() {
                  count += 1;
                });
                AwesomeNotifications().createNotification(
                    content: NotificationContent(
                      id: count,
                      channelKey: 'ppab_noti_download_result',
                      groupKey: 'ppab_noti_download_result',
                      title: 'title',
                      body: '$count',
                      autoDismissible: false,
                      displayOnForeground: true,
                      displayOnBackground: true,
                      locked: false,
                      progress: count,
                      notificationLayout: NotificationLayout.Default,
                    ),
                    actionButtons: [NotificationActionButton(key: "cancel", label: "Cancel", buttonType: ActionButtonType.KeepOnTop)]);
              }),
          ElevatedButton(
              child: const Text("show group 2"),
              onPressed: () async {
                setState(() {
                  count += 1;
                });
                AwesomeNotifications().createNotification(
                    content: NotificationContent(
                      id: count,
                      channelKey: 'ppab_noti_normal',
                      groupKey: 'ppab_noti_normal',
                      title: 'title',
                      body: '$count',
                      autoDismissible: false,
                      displayOnForeground: true,
                      displayOnBackground: true,
                      locked: false,
                      progress: count,
                      notificationLayout: NotificationLayout.Default,
                    ),
                    actionButtons: [NotificationActionButton(key: "cancel", label: "Cancel", buttonType: ActionButtonType.KeepOnTop)]);
              }),
        ],
      ),
    );
  }
}

whquddn55 avatar Mar 17 '22 13:03 whquddn55