feat: Enhance background geofence functionality with notifications and localization support

This commit is contained in:
Achintha Isuru
2026-03-13 21:44:39 -04:00
parent 6f57cae247
commit 8fcf1d9d98
12 changed files with 188 additions and 56 deletions

View File

@@ -12,8 +12,14 @@ class NotificationService extends BaseDeviceService {
/// The underlying notification plugin instance.
final FlutterLocalNotificationsPlugin _plugin;
/// Whether [initialize] has already been called.
bool _initialized = false;
/// Initializes notification channels and requests permissions.
///
/// Safe to call multiple times — subsequent calls are no-ops.
Future<void> initialize() async {
if (_initialized) return;
return action(() async {
const AndroidInitializationSettings androidSettings = AndroidInitializationSettings(
'@mipmap/ic_launcher',
@@ -28,15 +34,22 @@ class NotificationService extends BaseDeviceService {
iOS: iosSettings,
);
await _plugin.initialize(settings: settings);
_initialized = true;
});
}
/// Ensures the plugin is initialized before use.
Future<void> _ensureInitialized() async {
if (!_initialized) await initialize();
}
/// Displays a local notification with the given [title] and [body].
Future<void> showNotification({
required String title,
required String body,
int id = 0,
}) async {
await _ensureInitialized();
return action(() async {
const AndroidNotificationDetails androidDetails = AndroidNotificationDetails(
'krow_geofence',