-
Notifications
You must be signed in to change notification settings - Fork 55
Open
Description
when BackgroundLocationTrackerManager.handleBackgroundUpdated is called ,
i call api request to save this new location to server , but this request is repeated many times ,
how cal fix this bug
@pragma('vm:entry-point')
void backgroundCallback() {
BackgroundLocationTrackerManager.handleBackgroundUpdated(
(BackgroundLocationUpdateData data) async {
await providerContainer.read(currentLocationApiProvider).saveUserLocation(data);
});
}
final Provider<CurrentLocationApi> currentLocationApiProvider = Provider<CurrentLocationApi>(
(ProviderRef<CurrentLocationApi> ref) => CurrentLocationApi(ref.read));
class CurrentLocationApi {
final Reader read;
CurrentLocationApi(this.read);
Preferences get preferences => read(preferencesProvider);
ApiCore get apiCore => read(apiCoreProvider);
Future<void> saveUserLocation(
BackgroundLocationUpdateData data,
) async {
await preferences.init();
apiCore.init();
try {
await read(userApiProvider).saveUserLocation(data);
} catch (onError) {
debugPrint('$onError,,onError');
}
}
}i use river pod as state management @vanlooverenkoen
Metadata
Metadata
Assignees
Labels
No labels