Skip to content

fix(ui_auth): allow to pass EmailFormStyle via property #98

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 1 commit into from
Sep 5, 2023
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
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);
},
);
});
}