DeviceGeolocationMock class
In-memory fake of DeviceGeolocationPlatform for use in tests.
Apps depending on device_geolocation can import this class from
package:device_geolocation/testing.dart and install it as the active
platform implementation, removing the need to set up mock method
channels manually.
import 'package:device_geolocation/device_geolocation.dart';
import 'package:device_geolocation/testing.dart';
void main() {
late DeviceGeolocationMock mock;
setUp(() {
mock = DeviceGeolocationMock.install();
});
tearDown(() => mock.reset());
test('returns the position configured by the test', () async {
mock.position = mock.makePosition(latitude: 41.0, longitude: 2.0);
final p = await DeviceGeolocation.getCurrentPosition();
expect(p.latitude, 41.0);
});
}
- Inheritance
-
- Object
- PlatformInterface
- DeviceGeolocationPlatform
- DeviceGeolocationMock
- Mixed-in types
-
- MockPlatformInterfaceMixin
Constructors
Properties
- accuracy ↔ LocationAccuracyStatus
-
Value returned by getLocationAccuracy.
getter/setter pair
- hashCode → int
-
The hash code for this object.
no setterinherited
- lastForcedLocationManager ↔ bool
-
Whether getLastKnownPosition received
forceLocationManager: truethe last time it was called.getter/setter pair - lastForegroundNotificationConfig → ForegroundNotificationConfig?
-
Convenience accessor for the ForegroundNotificationConfig carried by
the most recent AndroidSettings passed to getPositionStream. Returns
nullwhen the last call did not use anAndroidSettingsinstance or the settings did not configure the foreground service.no setter - lastKnownPosition ↔ Position?
-
Value returned by getLastKnownPosition.
getter/setter pair
- lastLocationSettings ↔ LocationSettings?
-
LocationSettingslast passed to getCurrentPosition or getPositionStream.nullif no call has been made yet.getter/setter pair - lastPurposeKey ↔ String?
-
purposeKeylast passed to requestTemporaryFullAccuracy.getter/setter pair - lastRequestedBackground ↔ bool
-
Whether requestPermission received
requestBackground: truethe last time it was called. Useful for assertions.getter/setter pair - permission ↔ LocationPermission
-
Current permission state returned by checkPermission /
requestPermission.
getter/setter pair
- position ↔ Position?
-
Value returned by getCurrentPosition.
getter/setter pair
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- serviceEnabled ↔ bool
-
Value returned by isLocationServiceEnabled.
getter/setter pair
- settingsOpened ↔ bool
-
Value returned by openAppSettings and openLocationSettings.
getter/setter pair
- temporaryAccuracyResult ↔ LocationAccuracyStatus
-
Value returned by requestTemporaryFullAccuracy.
getter/setter pair
Methods
-
bearingBetween(
double startLatitude, double startLongitude, double endLatitude, double endLongitude) → double -
Initial bearing (forward azimuth) from start to end coordinates,
expressed in degrees.
inherited
-
checkPermission(
) → Future< LocationPermission> -
override
-
distanceBetween(
double startLatitude, double startLongitude, double endLatitude, double endLongitude) → double -
Great-circle distance between two coordinates in meters (Haversine).
inherited
-
emitPosition(
Position value) → void -
Pushes
valueto active getPositionStream listeners. -
emitServiceStatus(
ServiceStatus value) → void -
Pushes
valueto active getServiceStatusStream listeners. -
getCurrentPosition(
{LocationSettings? locationSettings}) → Future< Position> -
override
-
getLastKnownPosition(
{bool forceLocationManager = false}) → Future< Position?> -
override
-
getLocationAccuracy(
) → Future< LocationAccuracyStatus> -
override
-
getPositionStream(
{LocationSettings? locationSettings}) → Stream< Position> -
override
-
getServiceStatusStream(
) → Stream< ServiceStatus> -
override
-
isLocationServiceEnabled(
) → Future< bool> -
override
-
makePosition(
{double latitude = 0, double longitude = 0, DateTime? timestamp, double accuracy = 0, double altitude = 0, double altitudeAccuracy = 0, double heading = 0, double headingAccuracy = 0, double speed = 0, double speedAccuracy = 0, int? floor, bool isMocked = true}) → Position - Convenience constructor for a Position with sensible defaults.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
openAppSettings(
) → Future< bool> -
override
-
openLocationSettings(
) → Future< bool> -
override
-
requestPermission(
{bool requestBackground = false}) → Future< LocationPermission> -
override
-
requestTemporaryFullAccuracy(
{required String purposeKey}) → Future< LocationAccuracyStatus> -
override
-
reset(
) → Future< void> - Resets all configured state and closes active stream controllers.
-
setPosition(
Position value, {bool alsoLastKnown = true}) → void -
Sets position (and lastKnownPosition when
alsoLastKnownistrue). -
throwOnNext(
Object error) → void -
Causes the next platform call to throw
error. -
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Methods
-
install(
) → DeviceGeolocationMock - Installs a fresh DeviceGeolocationMock as the active platform implementation and returns it.