showProgressNotification static method

Future<void> showProgressNotification({
  1. required int notificationID,
  2. required String title,
  3. required double progress,
  4. required String localeCode,
})

Implementation

static Future<void> showProgressNotification({
  required int notificationID,
  required String title,
  required double progress,
  required String localeCode,
}) async {
  // Only update if progress changed significantly (5%)
  if (_lastProgress.containsKey(notificationID)) {
    final diff = (progress - _lastProgress[notificationID]!).abs();
    if (diff < 5.0 && progress < 100) {
      return; // Skip update
    }
  }

  _lastProgress[notificationID] = progress;

  await AwesomeNotifications().createNotification(
    content: NotificationContent(
      id: notificationID,
      channelKey: 'download_channel',
      title: title,
      body:
          '${AppStrings.get('progress', localeCode: localeCode)} ${progress.toInt()}%',
      progress: progress,
      notificationLayout: NotificationLayout.ProgressBar,
      locked: true, // Prevent dismissal
      autoDismissible: false,
    ),
  );
}