FakeOneTapLocation class final
Stands in for the platform in tests of apps that show a OneTapLocationButton.
While a fake is installed, buttons that are created call no platform channel and create no platform view, and OneTapLocationButton.checkAvailability reports the device that the fake describes. The target platform, defaultTargetPlatform, decides what the buttons show:
- On iOS, a button that stands in for the system button, with the size iosButtonSize. Where hasIOSSystemButton is false, nothing.
- On Android, the fallback button, or the widget that OneTapLocationButton.fallbackBuilder builds. Where hasAndroidSystemButton is true, a button that stands in for the system button instead, with the size of the system button.
- On the web and on other platforms, nothing.
A button that stands in for the system button resembles the fallback button and shows the English text of the label that the style selects. It shows what the system button would, but not how the system draws it, and on Android it is not hidden while other content covers it.
A tap adds a FakeLocationRequest to requests. The request reports
result once the tap has been handled, or waits until the test answers it.
The button receives each answer of the test before the call returns; pump a
frame to see its effect. While a request waits, the button accepts no taps,
and the onPressed callback given to OneTapLocationButton.fallbackBuilder
is null.
Install the fake before the buttons are created, and uninstall it when the test ends:
late FakeOneTapLocation location;
setUp(() {
location = FakeOneTapLocation.install();
addTearDown(location.uninstall);
});
testWidgets('fills in the coordinates after a tap', (
WidgetTester tester,
) async {
location.result = OneTapLocationGranted(
OneTapPosition(
latitude: 41.0082,
longitude: 28.9784,
timestamp: DateTime.utc(2026, 9, 16),
isPrecise: true,
),
);
await tester.pumpWidget(const MaterialApp(home: AddressForm()));
await tester.tap(find.byType(OneTapLocationButton));
await tester.pump();
expect(find.text('41.0082, 28.9784'), findsOneWidget);
});
Properties
- hasAndroidSystemButton ↔ bool
-
Whether the device has the system location button when the target
platform is Android, as devices with Android 17 and later do.
getter/setter pair
- hashCode → int
-
The hash code for this object.
no setterinherited
- hasIOSSystemButton ↔ bool
-
Whether the device shows the system location button when the target
platform is iOS.
getter/setter pair
- iosButtonSize ↔ Size
-
The size of the button that stands in for the system button on iOS.
getter/setter pair
- isPreciseLocationRestrictedToSystemButton ↔ bool
-
The value of
OneTapLocationAvailability.isPreciseLocationRestrictedToSystemButton
when the target platform is Android.
getter/setter pair
-
requests
→ List<
FakeLocationRequest> -
The requests made by taps on buttons that use this fake, oldest first.
no setter
- result ↔ OneTapLocationResult?
-
The result that a new request reports once the tap has been handled.
getter/setter pair
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
-
uninstall(
) → void - Removes this fake, so that buttons created afterwards reach the platform again.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Methods
-
install(
) → FakeOneTapLocation - Installs a new fake and returns it, replacing a fake that was installed before.