MaikuB / flutter_local_notifications

A Flutter plugin for displaying local notifications on Android, iOS, macOS and Linux
2.47k stars 1.4k forks source link

[HELP] Progress not updating after initial value in Samsung device #2381

Open abhinavsinghring opened 3 months ago

abhinavsinghring commented 3 months ago

Describe the bug I have used Dio package to download pdf file and show its progress in a notification. I have used the method mentioned in example file. https://github.com/MaikuB/flutter_local_notifications/blob/276c7bc8c2f1356afc25df7d7b215c17616fe40b/flutter_local_notifications/example/lib/main.dart#L1375 And it was working for me as expected, it was showing and updating the progress properly in other phones including emulator until I have used my app in Samsung phone. The problem I faced in that is when downloading starts, the notification pops up but doesn't update while in downloading widget(made by me to show progress in app) it shows and updates the value perfectly. And also there is other notification after the downloading is done which replaces the progress and notifies that download success, but this is also not showing in Samsung device I have faced this issue.

To Reproduce

onReceiveProgress: (received, total) async {
  if (total != -1) {
    if (!_cancelToken.isCancelled) {
      setState(() {
        _progress = '${((received / total) * 100).toInt()}%';
        _receivedSize = ((received/1024)/1024).toStringAsFixed(2);
        _totalSize = ((total/1024)/1024).toStringAsFixed(2);
      });
      const int maxProgress = 100;
      int i = ((received / total) * 100).toInt();
        await Future<void>.delayed(const Duration(milliseconds: 500), () async {
          final AndroidNotificationDetails androidPlatformChannelSpecifics =
              AndroidNotificationDetails('default', 'Default',
                  channelShowBadge: false,
                  importance: Importance.max,
                  priority: Priority.max,
                  onlyAlertOnce: true,
                  showProgress: true,
                  maxProgress: maxProgress,
                  playSound: false,
                  enableVibration: false,
                  progress: i,
                  number: 1,
                );
          final NotificationDetails platformChannelSpecifics =
              NotificationDetails(android: androidPlatformChannelSpecifics);
          await FlutterLocalNotificationsPlugin().show(
            69,
            "Downloading $_progress",
            null,
            platformChannelSpecifics,
          );
        });
    }
  }
},

When the Dio finished Downloading

await Dio().download(
  widget.docurl, 
  destPath,
  cancelToken: _cancelToken,
  deleteOnError: true,
  onReceiveProgress: // Above code
).then((value) async {
  setState(() {
    _downloading = false;
  });
  await FlutterLocalNotificationsPlugin().cancel(69);
  Future.delayed(Duration.zero , ()async{
    FlutterLocalNotificationsPlugin().show(
      69,
      "File downloaded",
      widget.doctitle,
      const NotificationDetails(
        android: AndroidNotificationDetails(
          'default',
          "Default",
          importance: Importance.max,
          priority: Priority.max,
          onlyAlertOnce: true,
          playSound: false,
          number: 1
        )
      ),
      payload: '''{"channelId":"default" ,"page":"downloads"}'''
    );
  });
});

Can anyone review my code for the expected function and help me improve this code if I'm wrong anywhere. Or if the code is fine, how do I know what is happening in that device at that time? @MaikuB Please help me!

abhinavsinghring commented 3 months ago

Also body is not showing if added in progress notification(currently in my device, haven't checked in other).