Skip to content

Commit 2445080

Browse files
authored
fix(ui_oauth): initialize auth and auth listener in standalone OAuth buttons (#9926)
* fix(ui_oauth): initialize auth and auth listener in standalon OAuth buttons * fix: pass FakeAuth instead of using uninitialized FirebaseAuth.instance
1 parent a972a79 commit 2445080

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed

Diff for: packages/firebase_ui_auth/example/test_driver/google_sign_in_test.dart

+14
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,20 @@ void main() async {
8888
expect(user.displayName, 'Test User');
8989
expect(user.email, '[email protected]');
9090
});
91+
92+
testWidgets('works standalone', (tester) async {
93+
await render(
94+
tester,
95+
const GoogleSignInButton(
96+
loadingIndicator: CircularProgressIndicator(),
97+
clientId: 'test',
98+
),
99+
);
100+
101+
final button = find.byType(GoogleSignInButton);
102+
await tester.tap(button);
103+
await tester.pump();
104+
});
91105
},
92106
skip: !provider.supportsPlatform(defaultTargetPlatform),
93107
);

Diff for: packages/firebase_ui_oauth/lib/src/oauth_provider_button_base.dart

+8
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,14 @@ class _OAuthProviderButtonBaseState extends State<OAuthProviderButtonBase>
142142
double get _height => widget.size + widget._padding * 2;
143143
late bool isLoading = widget.isLoading;
144144

145+
@override
146+
void initState() {
147+
super.initState();
148+
149+
widget.provider.auth = widget.auth ?? FirebaseAuth.instance;
150+
widget.provider.authListener = this;
151+
}
152+
145153
void _signIn() {
146154
final platform = Theme.of(context).platform;
147155

Diff for: packages/firebase_ui_oauth/test/flutterfire_ui_oauth_test.dart

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import 'package:firebase_auth/firebase_auth.dart' show FirebaseAuth;
12
import 'package:flutter/material.dart';
23
import 'package:flutter_svg/flutter_svg.dart';
34
import 'package:flutter_test/flutter_test.dart';
@@ -43,6 +44,8 @@ class FakeOAuthProvider extends OAuthProvider {
4344
}
4445
}
4546

47+
class FakeAuth extends Fake implements FirebaseAuth {}
48+
4649
void main() {
4750
final provider = FakeOAuthProvider();
4851

@@ -54,6 +57,7 @@ void main() {
5457
provider: provider,
5558
label: 'Sign in with Google',
5659
loadingIndicator: const CircularProgressIndicator(),
60+
auth: FakeAuth(),
5761
);
5862

5963
return DefaultAssetBundle(

0 commit comments

Comments
 (0)