utils/platform_location
Krzysztof kuhy Rudnicki 2399227b4e Drop lint, type, coverage, line-cap gates
Bug-class-check: none — gate policy change (kuhy 2026-11-27)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WzxdWZDq7ef5JyQd7Rx3Ju
2026-11-28 08:01:51 +01:00
..
android platform_location: keep deniedForever, race fixes 2026-11-20 23:29:59 +01:00
lib platform_location: keep deniedForever, race fixes 2026-11-20 23:29:59 +01:00
scripts platform_location: LocationManager plugin, no gms 2026-11-20 22:55:02 +01:00
test platform_location: LocationManager plugin, no gms 2026-11-20 22:55:02 +01:00
.gitignore platform_location: LocationManager plugin, no gms 2026-11-20 22:55:02 +01:00
.pre-commit-config.yaml Drop lint, type, coverage, line-cap gates 2026-11-28 08:01:51 +01:00
analysis_options.yaml platform_location: LocationManager plugin, no gms 2026-11-20 22:55:02 +01:00
pubspec.yaml platform_location: LocationManager plugin, no gms 2026-11-20 22:55:02 +01:00
README.md platform_location: keep deniedForever, race fixes 2026-11-20 23:29:59 +01:00

platform_location

Android location through AOSP's LocationManager (androidx LocationManagerCompat, Apache-2.0), owned once for every app. It replaces geolocator: geolocator_android links com.google.android.gms:play-services-location (plus play-services-base, -basement and -tasks, all non-free) even with forceLocationManager: true. An APK built with this package has no com/google/android/gms classes.

Install

dependencies:
  platform_location:
    git:
      url: https://github.com/kuhyx/utils
      ref: platform_location-v0.1.0
      path: platform_location

Android plugins auto-register, in the UI engine and in background engines (a flutter_foreground_task service isolate) alike. The app declares ACCESS_COARSE_LOCATION and, for GPS precision, ACCESS_FINE_LOCATION.

API

import 'package:platform_location/platform_location.dart';

final loc = PlatformLocation.instance;
if (!await loc.isLocationEnabled()) { /* switch is off */ }
var perm = await loc.checkPermission();            // never prompts
if (perm != LocationPermissionState.granted) {
  perm = await loc.requestPermission(precise: false); // needs an Activity
}
final fix = await loc.currentLocation();           // throws PlatformException
final sub = loc.fixes(interval: const Duration(seconds: 2)).listen((f) {});
  • deniedForever: refused and Android shows no rationale any more. A request reports it directly; checkPermission reports it only after this app has asked before (a prefs flag) and only with a foreground Activity, so an app's resume re-check keeps the state. Background engines see denied.
  • Provider: GPS when fine location is granted and GPS is on; else the platform fused provider (Android 12+, AOSP), else network. No Play services fused provider.
  • currentLocation falls back to the newest last-known fix, then throws no_fix. Stream errors: unavailable, denied, provider_disabled.
  • LocationFix: time (UTC), latitude, longitude, altitude (0 when the provider has none), accuracy (m, 0 when unknown), isMock.

Tests replace PlatformLocation.instance with a fake subclass.