@@ -73,6 +73,12 @@ class SupaEmailAuth extends StatefulWidget {
73
73
/// If set to `null` , a snack bar with error color will show up.
74
74
final void Function (Object error)? onError;
75
75
76
+ /// Callback for toggling between sign in and sign up
77
+ final void Function (bool isSigningIn)? onToggleSignIn;
78
+
79
+ /// Callback for toggling between sign-in/ sign-up and password recovery
80
+ final void Function (bool isRecoveringPassword)? onToggleRecoverPassword;
81
+
76
82
/// Set of additional fields to the signup form that will become
77
83
/// part of the user_metadata
78
84
final List <MetaDataField >? metadataFields;
@@ -91,6 +97,8 @@ class SupaEmailAuth extends StatefulWidget {
91
97
required this .onSignUpComplete,
92
98
this .onPasswordResetEmailSent,
93
99
this .onError,
100
+ this .onToggleSignIn,
101
+ this .onToggleRecoverPassword,
94
102
this .metadataFields,
95
103
this .extraMetadata,
96
104
this .localization = const SupaEmailAuthLocalization (),
@@ -109,8 +117,9 @@ class _SupaEmailAuthState extends State<SupaEmailAuth> {
109
117
bool _isLoading = false ;
110
118
111
119
/// The user has pressed forgot password button
112
- bool _forgotPassword = false ;
120
+ bool _isRecoveringPassword = false ;
113
121
122
+ /// Whether the user is signing in or signing up
114
123
bool _isSigningIn = true ;
115
124
116
125
@override
@@ -142,8 +151,9 @@ class _SupaEmailAuthState extends State<SupaEmailAuth> {
142
151
TextFormField (
143
152
keyboardType: TextInputType .emailAddress,
144
153
autofillHints: const [AutofillHints .email],
145
- textInputAction:
146
- _forgotPassword ? TextInputAction .done : TextInputAction .next,
154
+ textInputAction: _isRecoveringPassword
155
+ ? TextInputAction .done
156
+ : TextInputAction .next,
147
157
validator: (value) {
148
158
if (value == null ||
149
159
value.isEmpty ||
@@ -158,7 +168,7 @@ class _SupaEmailAuthState extends State<SupaEmailAuth> {
158
168
),
159
169
controller: _emailController,
160
170
),
161
- if (! _forgotPassword ) ...[
171
+ if (! _isRecoveringPassword ) ...[
162
172
spacer (16 ),
163
173
TextFormField (
164
174
autofillHints: _isSigningIn
@@ -261,8 +271,9 @@ class _SupaEmailAuthState extends State<SupaEmailAuth> {
261
271
TextButton (
262
272
onPressed: () {
263
273
setState (() {
264
- _forgotPassword = true ;
274
+ _isRecoveringPassword = true ;
265
275
});
276
+ widget.onToggleRecoverPassword? .call (_isRecoveringPassword);
266
277
},
267
278
child: Text (localization.forgotPassword),
268
279
),
@@ -271,16 +282,18 @@ class _SupaEmailAuthState extends State<SupaEmailAuth> {
271
282
key: const ValueKey ('toggleSignInButton' ),
272
283
onPressed: () {
273
284
setState (() {
274
- _forgotPassword = false ;
285
+ _isRecoveringPassword = false ;
275
286
_isSigningIn = ! _isSigningIn;
276
287
});
288
+ widget.onToggleSignIn? .call (_isSigningIn);
289
+ widget.onToggleRecoverPassword? .call (_isRecoveringPassword);
277
290
},
278
291
child: Text (_isSigningIn
279
292
? localization.dontHaveAccount
280
293
: localization.haveAccount),
281
294
),
282
295
],
283
- if (_isSigningIn && _forgotPassword ) ...[
296
+ if (_isSigningIn && _isRecoveringPassword ) ...[
284
297
spacer (16 ),
285
298
ElevatedButton (
286
299
onPressed: () async {
@@ -302,7 +315,7 @@ class _SupaEmailAuthState extends State<SupaEmailAuth> {
302
315
if (! context.mounted) return ;
303
316
context.showSnackBar (localization.passwordResetSent);
304
317
setState (() {
305
- _forgotPassword = false ;
318
+ _isRecoveringPassword = false ;
306
319
});
307
320
} on AuthException catch (error) {
308
321
widget.onError? .call (error);
@@ -322,7 +335,7 @@ class _SupaEmailAuthState extends State<SupaEmailAuth> {
322
335
TextButton (
323
336
onPressed: () {
324
337
setState (() {
325
- _forgotPassword = false ;
338
+ _isRecoveringPassword = false ;
326
339
});
327
340
},
328
341
child: Text (localization.backToSignIn),
0 commit comments