2025-05-10 11:16:46 -07:00
|
|
|
import 'dart:developer' as developer;
|
|
|
|
|
|
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
import 'package:quick_actions/quick_actions.dart';
|
2025-05-10 11:26:42 -07:00
|
|
|
import 'package:flutter_background_geolocation/flutter_background_geolocation.dart' as bg;
|
2025-05-10 11:16:46 -07:00
|
|
|
|
2025-06-05 23:15:05 -07:00
|
|
|
import 'l10n/app_localizations.dart';
|
|
|
|
|
|
2025-05-10 11:16:46 -07:00
|
|
|
class QuickActionsInitializer extends StatefulWidget {
|
|
|
|
|
const QuickActionsInitializer({super.key});
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
State<QuickActionsInitializer> createState() => _QuickActionsInitializerState();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class _QuickActionsInitializerState extends State<QuickActionsInitializer> {
|
|
|
|
|
final QuickActions quickActions = QuickActions();
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
void initState() {
|
|
|
|
|
super.initState();
|
2025-05-10 11:26:42 -07:00
|
|
|
quickActions.initialize((shortcutType) async {
|
2025-05-10 11:16:46 -07:00
|
|
|
developer.log('action $shortcutType');
|
|
|
|
|
switch (shortcutType) {
|
|
|
|
|
case 'start':
|
2025-05-10 11:26:42 -07:00
|
|
|
bg.BackgroundGeolocation.start();
|
2025-05-10 11:16:46 -07:00
|
|
|
case 'stop':
|
2025-05-10 11:26:42 -07:00
|
|
|
bg.BackgroundGeolocation.stop();
|
2025-05-10 11:16:46 -07:00
|
|
|
case 'sos':
|
2025-05-10 11:26:42 -07:00
|
|
|
try {
|
2025-05-31 22:23:11 -07:00
|
|
|
await bg.BackgroundGeolocation.getCurrentPosition(samples: 1, persist: true, extras: {'alarm': 'sos'});
|
2025-05-10 11:26:42 -07:00
|
|
|
await bg.BackgroundGeolocation.sync();
|
|
|
|
|
} catch (error) {
|
|
|
|
|
developer.log('Failed to send alert', error: error);
|
|
|
|
|
}
|
2025-05-10 11:16:46 -07:00
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
void didChangeDependencies() {
|
|
|
|
|
super.didChangeDependencies();
|
|
|
|
|
final localizations = AppLocalizations.of(context)!;
|
|
|
|
|
quickActions.setShortcutItems(<ShortcutItem>[
|
|
|
|
|
ShortcutItem(type: 'start', localizedTitle: localizations.startAction, icon: 'play'),
|
2025-05-10 11:26:42 -07:00
|
|
|
ShortcutItem(type: 'stop', localizedTitle: localizations.stopAction, icon: 'stop'),
|
|
|
|
|
ShortcutItem(type: 'sos', localizedTitle: localizations.sosAction, icon: 'exclamation'),
|
2025-05-10 11:16:46 -07:00
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
|
return const SizedBox.shrink();
|
|
|
|
|
}
|
|
|
|
|
}
|