Skip to content

fix(ui_oauth): initialize auth and auth listener in standalone OAuth buttons #9926

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,20 @@ void main() async {
expect(user.displayName, 'Test User');
expect(user.email, '[email protected]');
});

testWidgets('works standalone', (tester) async {
await render(
tester,
const GoogleSignInButton(
loadingIndicator: CircularProgressIndicator(),
clientId: 'test',
),
);

final button = find.byType(GoogleSignInButton);
await tester.tap(button);
await tester.pump();
});
},
skip: !provider.supportsPlatform(defaultTargetPlatform),
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,14 @@ class _OAuthProviderButtonBaseState extends State<OAuthProviderButtonBase>
double get _height => widget.size + widget._padding * 2;
late bool isLoading = widget.isLoading;

@override
void initState() {
super.initState();

widget.provider.auth = widget.auth ?? FirebaseAuth.instance;
widget.provider.authListener = this;
}

void _signIn() {
final platform = Theme.of(context).platform;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:firebase_auth/firebase_auth.dart' show FirebaseAuth;
import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:flutter_test/flutter_test.dart';
Expand Down Expand Up @@ -43,6 +44,8 @@ class FakeOAuthProvider extends OAuthProvider {
}
}

class FakeAuth extends Fake implements FirebaseAuth {}

void main() {
final provider = FakeOAuthProvider();

Expand All @@ -54,6 +57,7 @@ void main() {
provider: provider,
label: 'Sign in with Google',
loadingIndicator: const CircularProgressIndicator(),
auth: FakeAuth(),
);

return DefaultAssetBundle(
Expand Down