feat: Enhance background geofence functionality with notifications and localization support
This commit is contained in:
@@ -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',
|
||||
|
||||
Reference in New Issue
Block a user