Skip to content

Commit 88c31a3

Browse files
authored
fix(ui_auth): allow to pass EmailFormStyle via property (#98)
1 parent ef0cff7 commit 88c31a3

File tree

2 files changed

+101
-16
lines changed

2 files changed

+101
-16
lines changed

packages/firebase_ui_auth/lib/src/widgets/email_form.dart

+41-4
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,37 @@ class EmailForm extends StatelessWidget {
100100
/// A label that would be used for the "Sign in" button.
101101
final String? actionButtonLabelOverride;
102102

103+
/// An object that is being used to apply styling configuration to the email
104+
/// form.
105+
///
106+
/// Alternatively [FirebaseUITheme] could be used to provide styling
107+
/// configuration.
108+
/// ```dart
109+
/// runApp(
110+
/// const FirebaseUITheme(
111+
/// styles: {
112+
/// EmailFormStyle(signInButtonVariant: ButtonVariant.text),
113+
/// },
114+
/// child: MaterialApp(
115+
/// home: MyScreen(),
116+
/// ),
117+
/// ),
118+
/// );
119+
///
120+
/// class MyScreen extends StatelessWidget {
121+
/// @override
122+
/// Widget build(BuildContext context) {
123+
/// return Scaffold(
124+
/// appBar: AppBar(
125+
/// title: Text('Email sign in'),
126+
/// ),
127+
/// body: Center(child: EmailForm()),
128+
/// );
129+
/// }
130+
/// }
131+
/// ```
132+
final EmailFormStyle? style;
133+
103134
/// {@macro ui.auth.widgets.email_form}
104135
const EmailForm({
105136
super.key,
@@ -109,6 +140,7 @@ class EmailForm extends StatelessWidget {
109140
this.onSubmit,
110141
this.email,
111142
this.actionButtonLabelOverride,
143+
this.style,
112144
});
113145

114146
@override
@@ -120,6 +152,7 @@ class EmailForm extends StatelessWidget {
120152
email: email,
121153
onSubmit: onSubmit,
122154
actionButtonLabelOverride: actionButtonLabelOverride,
155+
style: style,
123156
);
124157

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

144177
final String? actionButtonLabelOverride;
145178

179+
final EmailFormStyle? style;
180+
146181
const _SignInFormContent({
147182
this.auth,
148183
this.onSubmit,
149184
this.action,
150185
this.email,
151186
this.provider,
152187
this.actionButtonLabelOverride,
188+
this.style,
153189
});
154190

155191
@override
@@ -268,10 +304,11 @@ class _SignInFormContentState extends State<_SignInFormContent> {
268304
Builder(
269305
builder: (context) {
270306
final state = AuthState.of(context);
271-
final style = FirebaseUIStyle.ofType<EmailFormStyle>(
272-
context,
273-
const EmailFormStyle(),
274-
);
307+
final style = widget.style ??
308+
FirebaseUIStyle.ofType<EmailFormStyle>(
309+
context,
310+
const EmailFormStyle(),
311+
);
275312

276313
return LoadingButton(
277314
variant: style.signInButtonVariant,

packages/firebase_ui_auth/test/widgets/email_form_test.dart

+60-12
Original file line numberDiff line numberDiff line change
@@ -42,18 +42,66 @@ void main() {
4242
);
4343
});
4444

45-
testWidgets('respects the EmailFormStyle', (tester) async {
46-
await tester.pumpWidget(
47-
FirebaseUITheme(
48-
styles: const {
49-
EmailFormStyle(signInButtonVariant: ButtonVariant.filled)
50-
},
51-
child: widget,
52-
),
53-
);
45+
testWidgets(
46+
'respects EmailFormStyle passed to FirebaseUITheme',
47+
(tester) async {
48+
await tester.pumpWidget(
49+
FirebaseUITheme(
50+
styles: const {
51+
EmailFormStyle(signInButtonVariant: ButtonVariant.filled)
52+
},
53+
child: widget,
54+
),
55+
);
5456

55-
final button = find.byType(ElevatedButton);
56-
expect(button, findsOneWidget);
57-
});
57+
final button = find.byType(ElevatedButton);
58+
expect(button, findsOneWidget);
59+
},
60+
);
61+
62+
testWidgets(
63+
'respects EmailFormStyle passed via property',
64+
(tester) async {
65+
await tester.pumpWidget(
66+
widget = TestMaterialApp(
67+
child: EmailForm(
68+
auth: MockAuth(),
69+
action: AuthAction.signIn,
70+
style: const EmailFormStyle(
71+
signInButtonVariant: ButtonVariant.filled,
72+
),
73+
),
74+
),
75+
);
76+
77+
final button = find.byType(ElevatedButton);
78+
expect(button, findsOneWidget);
79+
},
80+
);
81+
82+
testWidgets(
83+
'EmailFormStyle passed via property is higher priority',
84+
(tester) async {
85+
await tester.pumpWidget(
86+
TestMaterialApp(
87+
child: FirebaseUITheme(
88+
styles: const {
89+
EmailFormStyle(signInButtonVariant: ButtonVariant.text)
90+
},
91+
child: EmailForm(
92+
auth: MockAuth(),
93+
action: AuthAction.signIn,
94+
style: const EmailFormStyle(
95+
signInButtonVariant: ButtonVariant.filled,
96+
),
97+
),
98+
),
99+
),
100+
);
101+
102+
final button = find.byType(ElevatedButton);
103+
expect(button, findsOneWidget);
104+
},
105+
);
58106
});
59107
}

0 commit comments

Comments
 (0)