showTrackingNotification static method
Future<bool>
showTrackingNotification(
{ - String? androidNotificationTitle,
- String? androidNotificationContent,
})
Implementation
static Future<bool> showTrackingNotification({
final String? androidNotificationTitle,
final String? androidNotificationContent,
}) async {
try {
AndroidNotificationDetails androidNotificationDetails =
AndroidNotificationDetails(
'step_tracker_channel',
androidNotificationTitle ?? 'Step Tracker',
channelDescription: androidNotificationContent ?? 'Tracking your steps',
importance: Importance.max,
priority: Priority.max,
ongoing: true,
autoCancel: false,
enableVibration: true,
playSound: false,
visibility: NotificationVisibility.public,
// Critical for non-dismissable notifications:
channelShowBadge: false,
fullScreenIntent: true, // Makes it more persistent
timeoutAfter: null, // Never times out
showWhen: false,
when: null,
additionalFlags: Int32List.fromList([
1 << 2, // FLAG_NO_CLEAR - This is crucial
]),
);
await _notifications.show(
1,
'Step Tracker Active',
'Tracking your steps in the background',
NotificationDetails(android: androidNotificationDetails),
);
return true;
} catch (e) {
return false;
}
}