Skip to content

Commit

Permalink
fix(ui_auth): allow to pass EmailFormStyle via property (#98)
Browse files Browse the repository at this point in the history
  • Loading branch information
lesnitsky authored Sep 5, 2023
1 parent ef0cff7 commit 88c31a3
Show file tree
Hide file tree
Showing 2 changed files with 101 additions and 16 deletions.
45 changes: 41 additions & 4 deletions packages/firebase_ui_auth/lib/src/widgets/email_form.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -109,6 +140,7 @@ class EmailForm extends StatelessWidget {
this.onSubmit,
this.email,
this.actionButtonLabelOverride,
this.style,
});

@override
Expand All @@ -120,6 +152,7 @@ class EmailForm extends StatelessWidget {
email: email,
onSubmit: onSubmit,
actionButtonLabelOverride: actionButtonLabelOverride,
style: style,
);

return AuthFlowBuilder<EmailAuthController>(
Expand All @@ -143,13 +176,16 @@ class _SignInFormContent extends StatefulWidget {

final String? actionButtonLabelOverride;

final EmailFormStyle? style;

const _SignInFormContent({
this.auth,
this.onSubmit,
this.action,
this.email,
this.provider,
this.actionButtonLabelOverride,
this.style,
});

@override
Expand Down Expand Up @@ -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,
Expand Down
72 changes: 60 additions & 12 deletions packages/firebase_ui_auth/test/widgets/email_form_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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);
},
);
});
}

0 comments on commit 88c31a3

Please sign in to comment.