diff --git a/packages/firebase_ui_auth/lib/src/widgets/email_form.dart b/packages/firebase_ui_auth/lib/src/widgets/email_form.dart index 3718af5e..434517d0 100644 --- a/packages/firebase_ui_auth/lib/src/widgets/email_form.dart +++ b/packages/firebase_ui_auth/lib/src/widgets/email_form.dart @@ -100,6 +100,37 @@ class EmailForm extends StatelessWidget { /// A label that would be used for the "Sign in" button. final String? actionButtonLabelOverride; + /// An object that is being used to apply styling configuration to the email + /// form. + /// + /// Alternatively [FirebaseUITheme] could be used to provide styling + /// configuration. + /// ```dart + /// runApp( + /// const FirebaseUITheme( + /// styles: { + /// EmailFormStyle(signInButtonVariant: ButtonVariant.text), + /// }, + /// child: MaterialApp( + /// home: MyScreen(), + /// ), + /// ), + /// ); + /// + /// class MyScreen extends StatelessWidget { + /// @override + /// Widget build(BuildContext context) { + /// return Scaffold( + /// appBar: AppBar( + /// title: Text('Email sign in'), + /// ), + /// body: Center(child: EmailForm()), + /// ); + /// } + /// } + /// ``` + final EmailFormStyle? style; + /// {@macro ui.auth.widgets.email_form} const EmailForm({ super.key, @@ -109,6 +140,7 @@ class EmailForm extends StatelessWidget { this.onSubmit, this.email, this.actionButtonLabelOverride, + this.style, }); @override @@ -120,6 +152,7 @@ class EmailForm extends StatelessWidget { email: email, onSubmit: onSubmit, actionButtonLabelOverride: actionButtonLabelOverride, + style: style, ); return AuthFlowBuilder<EmailAuthController>( @@ -143,6 +176,8 @@ class _SignInFormContent extends StatefulWidget { final String? actionButtonLabelOverride; + final EmailFormStyle? style; + const _SignInFormContent({ this.auth, this.onSubmit, @@ -150,6 +185,7 @@ class _SignInFormContent extends StatefulWidget { this.email, this.provider, this.actionButtonLabelOverride, + this.style, }); @override @@ -268,10 +304,11 @@ class _SignInFormContentState extends State<_SignInFormContent> { Builder( builder: (context) { final state = AuthState.of(context); - final style = FirebaseUIStyle.ofType<EmailFormStyle>( - context, - const EmailFormStyle(), - ); + final style = widget.style ?? + FirebaseUIStyle.ofType<EmailFormStyle>( + context, + const EmailFormStyle(), + ); return LoadingButton( variant: style.signInButtonVariant, diff --git a/packages/firebase_ui_auth/test/widgets/email_form_test.dart b/packages/firebase_ui_auth/test/widgets/email_form_test.dart index 0c81df17..5d3f0589 100644 --- a/packages/firebase_ui_auth/test/widgets/email_form_test.dart +++ b/packages/firebase_ui_auth/test/widgets/email_form_test.dart @@ -42,18 +42,66 @@ void main() { ); }); - testWidgets('respects the EmailFormStyle', (tester) async { - await tester.pumpWidget( - FirebaseUITheme( - styles: const { - EmailFormStyle(signInButtonVariant: ButtonVariant.filled) - }, - child: widget, - ), - ); + testWidgets( + 'respects EmailFormStyle passed to FirebaseUITheme', + (tester) async { + await tester.pumpWidget( + FirebaseUITheme( + styles: const { + EmailFormStyle(signInButtonVariant: ButtonVariant.filled) + }, + child: widget, + ), + ); - final button = find.byType(ElevatedButton); - expect(button, findsOneWidget); - }); + final button = find.byType(ElevatedButton); + expect(button, findsOneWidget); + }, + ); + + testWidgets( + 'respects EmailFormStyle passed via property', + (tester) async { + await tester.pumpWidget( + widget = TestMaterialApp( + child: EmailForm( + auth: MockAuth(), + action: AuthAction.signIn, + style: const EmailFormStyle( + signInButtonVariant: ButtonVariant.filled, + ), + ), + ), + ); + + final button = find.byType(ElevatedButton); + expect(button, findsOneWidget); + }, + ); + + testWidgets( + 'EmailFormStyle passed via property is higher priority', + (tester) async { + await tester.pumpWidget( + TestMaterialApp( + child: FirebaseUITheme( + styles: const { + EmailFormStyle(signInButtonVariant: ButtonVariant.text) + }, + child: EmailForm( + auth: MockAuth(), + action: AuthAction.signIn, + style: const EmailFormStyle( + signInButtonVariant: ButtonVariant.filled, + ), + ), + ), + ), + ); + + final button = find.byType(ElevatedButton); + expect(button, findsOneWidget); + }, + ); }); }