Skip to content

infinite repeat backgroundCallback when First time only install app for any device android  #54

@AhkamKhallaf

Description

@AhkamKhallaf

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

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions