@@ -12,18 +12,28 @@ import 'package:ht_main/shared/constants/app_spacing.dart';
12
12
/// {@endtemplate}
13
13
class EmailSignInPage extends StatelessWidget {
14
14
/// {@macro email_sign_in_page}
15
- const EmailSignInPage ({super .key});
15
+ const EmailSignInPage ({
16
+ required this .isLinkingContext, // Accept the flag
17
+ super .key,
18
+ });
19
+
20
+ /// Whether this page is being shown in the account linking context.
21
+ final bool isLinkingContext;
16
22
17
23
@override
18
24
Widget build (BuildContext context) {
19
25
// Assuming AuthenticationBloc is provided by the parent route (AuthenticationPage)
20
26
// If not, it needs to be provided here or higher up.
21
- return const _EmailSignInView ();
27
+ // Pass the flag down to the view.
28
+ return _EmailSignInView (isLinkingContext: isLinkingContext);
22
29
}
23
30
}
24
31
25
32
class _EmailSignInView extends StatelessWidget {
26
- const _EmailSignInView ();
33
+ // Accept the flag from the parent page.
34
+ const _EmailSignInView ({required this .isLinkingContext});
35
+
36
+ final bool isLinkingContext;
27
37
28
38
@override
29
39
Widget build (BuildContext context) {
@@ -33,6 +43,24 @@ class _EmailSignInView extends StatelessWidget {
33
43
return Scaffold (
34
44
appBar: AppBar (
35
45
title: Text (l10n.emailSignInPageTitle), // New l10n key needed
46
+ // Add a custom leading back button to control navigation based on context.
47
+ leading: IconButton (
48
+ icon: const Icon (Icons .arrow_back),
49
+ tooltip: MaterialLocalizations .of (context).backButtonTooltip, // Accessibility
50
+ onPressed: () {
51
+ // Navigate back differently based on the context.
52
+ if (isLinkingContext) {
53
+ // If linking, go back to Auth page preserving the linking query param.
54
+ context.goNamed (
55
+ Routes .authenticationName,
56
+ queryParameters: {'context' : 'linking' },
57
+ );
58
+ } else {
59
+ // If normal sign-in, just go back to the Auth page.
60
+ context.goNamed (Routes .authenticationName);
61
+ }
62
+ },
63
+ ),
36
64
),
37
65
body: SafeArea (
38
66
child: BlocConsumer <AuthenticationBloc , AuthenticationState >(
@@ -52,10 +80,12 @@ class _EmailSignInView extends StatelessWidget {
52
80
}
53
81
},
54
82
// BuildWhen prevents unnecessary rebuilds if only listening
55
- buildWhen: (previous, current) =>
56
- current is AuthenticationInitial ||
57
- current is AuthenticationLinkSending ||
58
- current is AuthenticationFailure , // Rebuild on failure to re-enable form
83
+ buildWhen:
84
+ (previous, current) =>
85
+ current is AuthenticationInitial ||
86
+ current is AuthenticationLinkSending ||
87
+ current
88
+ is AuthenticationFailure , // Rebuild on failure to re-enable form
59
89
builder: (context, state) {
60
90
final isLoading = state is AuthenticationLinkSending ;
61
91
@@ -110,10 +140,10 @@ class _EmailLinkFormState extends State<_EmailLinkForm> {
110
140
void _submitForm () {
111
141
if (_formKey.currentState! .validate ()) {
112
142
context.read <AuthenticationBloc >().add (
113
- AuthenticationSendSignInLinkRequested (
114
- email: _emailController.text.trim (),
115
- ),
116
- );
143
+ AuthenticationSendSignInLinkRequested (
144
+ email: _emailController.text.trim (),
145
+ ),
146
+ );
117
147
}
118
148
}
119
149
@@ -140,22 +170,27 @@ class _EmailLinkFormState extends State<_EmailLinkForm> {
140
170
validator: (value) {
141
171
if (value == null || value.isEmpty || ! value.contains ('@' )) {
142
172
// Add a specific validation error message key if needed
143
- return l10n.accountLinkingEmailValidationError; // Re-use for now
173
+ return l10n
174
+ .accountLinkingEmailValidationError; // Re-use for now
144
175
}
145
176
return null ;
146
177
},
147
- onFieldSubmitted: (_) => _submitForm (), // Allow submitting from keyboard
178
+ onFieldSubmitted:
179
+ (_) => _submitForm (), // Allow submitting from keyboard
148
180
),
149
181
const SizedBox (height: AppSpacing .lg),
150
182
ElevatedButton (
151
183
onPressed: widget.isLoading ? null : _submitForm,
152
- child: widget.isLoading
153
- ? const SizedBox (
154
- height: 24 , // Consistent height
155
- width: 24 ,
156
- child: CircularProgressIndicator (strokeWidth: 2 ),
157
- )
158
- : Text (l10n.authenticationSendLinkButton), // Re-use existing key
184
+ child:
185
+ widget.isLoading
186
+ ? const SizedBox (
187
+ height: 24 , // Consistent height
188
+ width: 24 ,
189
+ child: CircularProgressIndicator (strokeWidth: 2 ),
190
+ )
191
+ : Text (
192
+ l10n.authenticationSendLinkButton,
193
+ ), // Re-use existing key
159
194
),
160
195
],
161
196
),
0 commit comments