FakeBaabaLocation class
A BaabaLocation for tests, with no platform channels.
It is the real implementation running on an in-memory platform, so the flow, filters, fallback, cache and geocoding queue behave exactly as in production. You script the device and the user:
import 'package:baaba_location/testing.dart';
final location = FakeBaabaLocation(permission: LocationAccess.denied)
..simulateUserResponse(FakeUserResponse.grantPrecise)
..emit(Position(latitude: 31.52, longitude: 74.35, timestamp: DateTime.now()));
final result = await location.get();
expect(result.isSuccess, isTrue);
expect(result.steps, contains(LocationStep.requestedPermission));
expect(location.callsTo('get'), hasLength(1));
Every method call is recorded in calls.
- Implemented types
Constructors
- FakeBaabaLocation({LocationConfig config = const LocationConfig(), LocationAccess permission = LocationAccess.grantedPrecise, bool serviceEnabled = true, Position? currentFix, bool supported = true, DateTime clock()?})
Properties
-
calls
→ List<
FakeLocationCall> -
Every call, in order.
final
- config → LocationConfig
-
no setteroverride
- hashCode → int
-
The hash code for this object.
no setterinherited
- platform → InMemoryLocationPlatform
-
The simulated device. Reach in for anything the helpers don't cover.
final
- prompter ↔ InMemoryPrompter
-
The simulated dialogs; counts how often each was shown.
latefinal
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
-
serviceStatusStream
→ Stream<
bool> -
Whether location services are on.
no setteroverride
-
statusStream
→ Stream<
LocationStatus> -
Services, permission and pause changes.
no setteroverride
Methods
-
addressFrom(
Position? position, {double? lat, double? lng, Locale? locale, Object? consumer}) → Future< AddressResult> -
Coordinates → address. Pass a
positionorlatandlng.override -
applyConfig(
LocationConfig config) → Future< void> -
Swaps the configuration; what init calls.
override
-
callsTo(
String method) → List< FakeLocationCall> -
checkPermission(
) → Future< LocationAccess> -
The permission and its precision, with no UI.
override
-
clearStoredLocation(
) → Future< void> -
Deletes the stored last known location and the address cache. Call on
logout and account switch.
override
-
currentPosition(
{LocationAccuracy accuracy = LocationAccuracy.high, Duration timeout = const Duration(seconds: 15), Duration? maxAge}) → Future< LocationResult> -
One fix with no UI. A missing permission returns
permissionDeniedat once. Reuses a fix younger thanmaxAgewithout waking the GPS; falls back to the last known location when no fix arrives withintimeout.override -
diagnose(
{bool tryFix = true}) → Future< LocationDiagnostics> -
The setup doctor. In debug builds it also prints a checklist with the
exact snippet for every problem. With
tryFix, it tries a short fix (no UI) and a reverse geocode of it.override -
dispose(
) → Future< void> -
Stops every stream and native listener. The instance stays usable: the
next call starts again.
override
-
emit(
Position position) → void - A fix from the device: delivered to running streams (through the filters), and returned by the next fix request.
-
ensurePermission(
{bool precise = false, BuildContext? context}) → Future< LocationAccess> -
Runs the permission flow (
AppPermission.location), and the precise upgrade whenprecise.override -
failNext(
LocationFailureReason reason) → void -
The next fix request fails with
reason. -
geocodingFails(
LocationFailureReason? reason) → void -
Every geocode fails with
reasonuntil called withnull. -
get(
{LocationProfile? profile, bool withAddress = false, bool handlePermission = true, bool handleServices = true, LocationAccuracy? accuracy, Duration? maxAge, Duration? timeout, Locale? locale, BuildContext? context}) → Future< LocationResult> -
One location, with everything around it handled:
override
-
lastKnownPosition(
{Duration? maxAge}) → Future< LocationResult> -
The newer of the OS's and the package's stored last known location
(better accuracy wins when they are within 30 s), ignoring anything
older than
maxAge.noFixwhen there is none.override -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
openAppSettings(
) → Future< bool> -
override
-
openLocationSettings(
) → Future< bool> -
override
-
playRoute(
List< Position> route, {Duration interval = const Duration(seconds: 1)}) → Future<void> -
Emits
routeone fix at a time,intervalapart. -
positionsFrom(
String query, {Locale? locale, Object? consumer}) → Future< PositionsResult> -
Query → matching places, best first.
override
-
positionStream(
{LocationAccuracy accuracy = LocationAccuracy.high, double distanceFilter = 0, Duration interval = const Duration(seconds: 5), PositionFilters? filters, BackgroundLocation? background}) → Stream< Position> -
Fixes as they arrive. Broadcast; the native subscription is shared with
every other listener and stops with the last one.
override
-
requestPrecise(
{String? purposeKey}) → Future< LocationAccess> -
Asks for precise location where the platform allows: Android
re-request, iOS temporary full accuracy (needs
purposeKeyorLocationConfig.iosPrecisePurposeKey).override -
resolve(
LocationFailure failure, {BuildContext? context}) → Future< bool> -
Performs
failure.resolution: asks for permission, opens Settings, turns location on, offers the Play services update. Returns whether the problem is gone.fixConfiguration,retryLaterandnonereturnfalse.override -
serviceEnabled(
) → Future< bool> -
override
-
setBackground(
bool background) → void - The app went to the background (streams pause) or came back.
-
setCurrentFix(
Position? position) → void -
What the next fix request returns;
null= no fix arrives (timeout). -
setLastKnown(
Position position, {Duration age = Duration.zero}) → void - Sets both the OS's and the stored last known location.
-
setMisconfigured(
List< String> missing, {bool preciseDeclared = true}) → void - The app lacks these manifest / Info.plist entries.
-
setOnline(
bool? online) → void -
setOsLastKnown(
Position? position, {Duration age = Duration.zero}) → void -
setPermission(
LocationAccess access) → void -
setServiceEnabled(
bool enabled) → void -
setStoredLastKnown(
Position? position, {Duration age = Duration.zero, Address? address, bool ageReliable = true}) → void -
simulateUserResponse(
FakeUserResponse response) → void - Queues how the user answers the next prompt of that kind.
-
stubAddress(
Position position, Address address) → void -
stubPositions(
String query, List< Position> positions) → void -
timeoutNext(
) → void - The next fix request times out.
-
toString(
) → String -
A string representation of this object.
inherited
-
watch(
{LocationProfile? profile, bool withAddress = false, bool handlePermission = true, bool handleServices = true, LocationAccuracy? accuracy, Locale? locale, BuildContext? context, BackgroundLocation? background}) → Stream< LocationResult> -
Runs the same setup as get once, then streams results. A setup
failure is emitted as one failed result, and the stream closes.
override
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited