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 ↔ DeviceLocationAccuracyStatus
-
Value returned by getLocationAccuracy.
getter/setter pair
- hashCode → int
-
The hash code for this object.
no setterinherited
- lastDeviceLocationSettings ↔ DeviceLocationSettings?
-
DeviceLocationSettingslast passed to getCurrentPosition or getPositionStream.nullif no call has been made yet.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 - 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 ↔ DeviceLocationPermission
-
Current permission state returned by checkPermission /
requestPermission and emitted by getPermissionStream.
getter/setter pair
- position ↔ DevicePosition?
-
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
-
settingsOpenedStream
→ Stream<
bool> -
Stream that emits
truewhen a system settings panel is opened by this plugin andfalsewhen the app returns to the foreground.no setteroverride - temporaryAccuracyResult ↔ DeviceLocationAccuracyStatus
-
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< DeviceLocationPermission> -
override
-
distanceBetween(
double startLatitude, double startLongitude, double endLatitude, double endLongitude, {GeospatialAlgorithm algorithm = GeospatialAlgorithm.vincenty}) → double -
Great-circle distance between two coordinates in meters.
inherited
-
emitPermission(
DeviceLocationPermission value) → void -
Pushes
valueto active getPermissionStream listeners. -
emitPosition(
DevicePosition value) → void -
Pushes
valueto active getPositionStream listeners. -
emitServiceStatus(
DeviceLocationServiceStatus value) → void -
Pushes
valueto active getServiceStatusStream listeners. -
getCurrentPosition(
{DeviceLocationSettings? deviceLocationSettings}) → Future< DevicePosition> -
override
-
getLocationAccuracy(
) → Future< DeviceLocationAccuracyStatus> -
override
-
getPermissionStream(
{Duration pollingInterval = const Duration(seconds: 1)}) → Stream< DeviceLocationPermission> -
override
-
getPositionStream(
{DeviceLocationSettings? deviceLocationSettings}) → Stream< DevicePosition> -
override
-
getServiceStatusStream(
) → Stream< DeviceLocationServiceStatus> -
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}) → DevicePosition - Convenience constructor for a DevicePosition with sensible defaults.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
openAppSettings(
{DeviceGeolocationSettingsCallback? callback}) → Future< bool> -
override
-
openLocationSettings(
{DeviceGeolocationSettingsCallback? callback}) → Future< bool> -
override
-
requestPermission(
{bool requestBackground = false}) → Future< DeviceLocationPermission> -
override
-
requestTemporaryFullAccuracy(
{required String purposeKey}) → Future< DeviceLocationAccuracyStatus> -
override
-
reset(
) → Future< void> - Resets all configured state and closes active stream controllers.
-
setPosition(
DevicePosition value) → void -
Sets position to
value. -
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.