FakeAndroidSignInKit class
Answers AndroidSignInKit calls in tests, instead of Android's
Credential Manager, so you can test your login screens on any machine.
late FakeAndroidSignInKit fake;
setUp(() => fake = FakeAndroidSignInKit()..install());
tearDown(() => fake.uninstall());
testWidgets('Google sign-in opens the home page', (tester) async {
await tester.pumpWidget(const MyApp());
await tester.tap(find.byType(GoogleSignInButton));
await tester.pumpAndSettle();
expect(find.text('Hello, Test User'), findsOneWidget);
});
testWidgets('closing the sheet keeps the login page', (tester) async {
fake.nextError = CredentialErrorCode.canceled;
...
});
Every sheet "picks" what you set up: the Google account
(googleEmail, googleName), the first of passwords, or the
passkey. Set nextError to make the next sheet fail instead, and read
calls to check what the app asked for. While installed,
AndroidSignInKit.isSupported is true on every platform.
Constructors
-
FakeAndroidSignInKit({String googleEmail = 'test@example.com', String? googleName = 'Test User', List<
SavedPassword> passwords = const [], FakeSignInPick pick = FakeSignInPick.google, String passkeyResponseJson = _passkeyResponse, String? restoreKeyResponseJson, String? digitalCredentialJson}) -
A fake that signs in as
googleEmailand offerspasswords. Call install to use it.
Properties
-
calls
→ List<
FakeCall> -
Every call the app made, oldest first.
final
- digitalCredentialJson ↔ String?
-
What
getDigitalCredentialreturns. Null throws CredentialErrorCode.noCredential.getter/setter pair - googleEmail ↔ String
-
The Google account's email.
getter/setter pair
- googleName ↔ String?
-
The Google account's name.
getter/setter pair
- hashCode → int
-
The hash code for this object.
no setterinherited
-
methods
→ List<
String> -
The methods called, oldest first, such as
['initialize', 'signIn'].no setter - nextError ↔ CredentialErrorCode?
-
When set, the next call that shows a sheet fails with this code, as
if the user closed it (CredentialErrorCode.canceled) or the phone
were offline (CredentialErrorCode.network). It is cleared after one
use.
savePasswordreturns PasswordSaveResult.declined for CredentialErrorCode.canceled.getter/setter pair - passkeyResponseJson ↔ String
-
What
signInWithPasskeyandsignInreturn for a passkey.getter/setter pair -
passwords
→ List<
SavedPassword> -
The saved passwords.
getPasswordreturns the first, andsavePasswordadds to them.final - pick ↔ FakeSignInPick
-
What
signInreturns.getter/setter pair - restoreKeyResponseJson ↔ String?
-
What
getRestoreKeyreturns. Null means there is none.getter/setter pair - runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- storedUser ↔ String?
-
The stored user, as
AndroidSignInKitkeeps it between runs.getter/setter pair - tokenLifetime ↔ Duration
-
How long the ID tokens it hands out are valid. Make it short to test
getIdTokenrefreshing.getter/setter pair
Methods
-
idToken(
{String? nonce, Duration validFor = const Duration(hours: 1)}) → String -
An unsigned ID token with the usual Google claims, as
signInWithGooglereturns it here. Never accept such a token on a server. -
install(
) → void -
Starts answering
AndroidSignInKitcalls, after forgetting the user and settings of earlier tests. -
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 - Gives the calls back to Android.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited