flutter_local_notifications icon indicating copy to clipboard operation
flutter_local_notifications copied to clipboard

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

Open abhinavsinghring opened this issue 1 year ago • 1 comments

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 avatar Jul 29 '24 19:07 abhinavsinghring

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

abhinavsinghring avatar Jul 31 '24 15:07 abhinavsinghring

Sorry missed responding on this and don't know if you ended finding the solution but note I don't have capacity to help on issues specific to scenarios on how someones use a plugin with the app. It's better if you use other forums for help to do with your app-specific scenarios, especially when what you've described appears to be device-specific. In principle, if you trigger a notification to be shown/updated as you get information about the progress then that should update it. The example app demonstrates a similar scenario that simulates this by updating the same notification using the same ID. I've also tested updating a notification and this works as well

MaikuB avatar Jan 24 '25 12:01 MaikuB