flutterlocation
flutterlocation copied to clipboard
Notification not showing properly, always default
Despite of declaring changeNotificationOptions, it always returns its default value: "package name" "location background service running"
Tried adjusting it in different ways, this is the last one I tried. All other settings are fine.
@override
void initState() {
super.initState();
// WidgetsBinding.instance.addObserver(this);
_loadUserConfig().then((_) {
_fetchData();
// Initialize and start tracking user location
_locationService.trackUserLocation((LocationData currentLocation) {
// This function is called whenever a new location is available
_handleLocationUpdate(currentLocation);
});
});
}
Future<void> _loadUserConfig() async {
final appConfig = AppConfig();
await appConfig.initialize();
if (appConfig.userUuid == null) {
if (mounted) {
ScaffoldMessenger.of(context).showSnackBar(const SnackBar(
content: Text('El UUID del usuario es nulo, Por favor, ingrese nuevamente.'),
));
Navigator.of(context).pushReplacement(MaterialPageRoute(builder: (context) => const LoginScreen()));
}
} else {
setState(() {
userUuid = appConfig.userUuid;
location.enableBackgroundMode(enable: true);
location.changeSettings(
accuracy: LocationAccuracy.high,
interval: 10000,
distanceFilter: 10,
);
location.changeNotificationOptions(
channelName: 'Asset Location', title: 'Servicio de ubicación activado', iconName: 'ic_launcher', onTapBringToFront: true);
});
}
Tested on:
- Android API 29 and 30 in different Pixel emulators and in physical device Samsung A305G
Stack used:
dependencies:
flutter:
sdk: flutter
cupertino_icons: ^1.0.2
http: ^1.2.0
provider: ^6.1.1
shared_preferences: ^2.2.2
jwt_decode: ^0.3.1
flutter_map: ^6.1.0
latlong2: ^0.9.0
flutter_map_cancellable_tile_provider: ^2.0.0
location: ^5.0.3
intl: ^0.19.0
dart_ipify: ^1.1.1
mobile_scanner: ^3.5.7
Recently upgraded to this, but previously did not work either
Flutter 3.19.2 • channel stable • https://github.com/flutter/flutter.git
Framework • revision 7482962148 (4 days ago) • 2024-02-27 16:51:22 -0500
Engine • revision 04817c99c9
Tools • Dart 3.3.0 • DevTools 2.31.1