Skip to content

Commit d518969

Browse files
committed
fix(auth): Addresses the issue where the back/close button was missing when accessing the authentication page for account linking. Both the original routing issue and the missing button issue should now be resolved.
1 parent 66be3f2 commit d518969

File tree

2 files changed

+60
-57
lines changed

2 files changed

+60
-57
lines changed

lib/authentication/view/authentication_page.dart

Lines changed: 58 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ class AuthenticationPage extends StatelessWidget {
2121
required this.headline,
2222
required this.subHeadline,
2323
required this.showAnonymousButton,
24+
required this.isLinkingContext, // Add this parameter
2425
super.key,
2526
});
2627

@@ -33,20 +34,26 @@ class AuthenticationPage extends StatelessWidget {
3334
/// Whether to show the "Continue Anonymously" button.
3435
final bool showAnonymousButton;
3536

37+
/// Whether this page is being shown in the account linking context.
38+
final bool isLinkingContext; // Add this field
39+
3640
@override
3741
Widget build(BuildContext context) {
3842
// Provide the BLoC here if it's not already provided higher up
3943
// For this refactor, assuming it's provided by the route or App setup
4044
return BlocProvider(
4145
// Ensure BLoC is created only once per instance of this page if needed
4246
// If BLoC needs to persist across navigations, provide it higher up.
43-
create: (context) => AuthenticationBloc(
44-
authenticationRepository: context.read<HtAuthenticationRepository>(),
45-
),
47+
create:
48+
(context) => AuthenticationBloc(
49+
authenticationRepository:
50+
context.read<HtAuthenticationRepository>(),
51+
),
4652
child: _AuthenticationView(
4753
headline: headline,
4854
subHeadline: subHeadline,
4955
showAnonymousButton: showAnonymousButton,
56+
isLinkingContext: isLinkingContext, // Pass down the flag
5057
),
5158
);
5259
}
@@ -58,11 +65,13 @@ class _AuthenticationView extends StatelessWidget {
5865
required this.headline,
5966
required this.subHeadline,
6067
required this.showAnonymousButton,
68+
required this.isLinkingContext, // Add this parameter
6169
});
6270

6371
final String headline;
6472
final String subHeadline;
6573
final bool showAnonymousButton;
74+
final bool isLinkingContext; // Add this field
6675

6776
@override
6877
Widget build(BuildContext context) {
@@ -71,7 +80,21 @@ class _AuthenticationView extends StatelessWidget {
7180
final colorScheme = Theme.of(context).colorScheme;
7281

7382
return Scaffold(
74-
// Consider adding an AppBar if needed for context/navigation
83+
appBar: AppBar(
84+
backgroundColor: Colors.transparent,
85+
elevation: 0,
86+
// Conditionally add the leading close button only in linking context
87+
leading: isLinkingContext
88+
? IconButton(
89+
icon: const Icon(Icons.close),
90+
tooltip: MaterialLocalizations.of(context).closeButtonTooltip, // Accessibility
91+
onPressed: () {
92+
// Navigate back to the account page when close is pressed
93+
context.goNamed(Routes.accountName);
94+
},
95+
)
96+
: null, // No leading button if not linking (relies on system back if pushed)
97+
),
7598
body: SafeArea(
7699
child: BlocConsumer<AuthenticationBloc, AuthenticationState>(
77100
// Listener remains crucial for feedback (errors)
@@ -94,14 +117,18 @@ class _AuthenticationView extends StatelessWidget {
94117
// Email link success is handled in the dedicated email flow pages.
95118
},
96119
builder: (context, state) {
97-
final isLoading = state is AuthenticationLoading; // Simplified loading check
120+
final isLoading =
121+
state is AuthenticationLoading; // Simplified loading check
98122

99123
return Padding(
100-
padding: const EdgeInsets.all(AppSpacing.paddingLarge), // Use constant
124+
padding: const EdgeInsets.all(
125+
AppSpacing.paddingLarge,
126+
), // Use constant
101127
child: Center(
102128
child: SingleChildScrollView(
103129
child: Column(
104-
mainAxisAlignment: MainAxisAlignment.center, // Center vertically
130+
mainAxisAlignment:
131+
MainAxisAlignment.center, // Center vertically
105132
crossAxisAlignment: CrossAxisAlignment.stretch,
106133
children: [
107134
// --- Headline and Subheadline ---
@@ -117,41 +144,46 @@ class _AuthenticationView extends StatelessWidget {
117144
textAlign: TextAlign.center,
118145
),
119146
const SizedBox(height: AppSpacing.xxl), // Use constant
120-
121147
// --- Google Sign-In Button ---
122148
ElevatedButton.icon(
123-
icon: const Icon(Icons.g_mobiledata), // Placeholder icon
149+
icon: const Icon(
150+
Icons.g_mobiledata,
151+
), // Placeholder icon
124152
label: Text(l10n.authenticationGoogleSignInButton),
125-
onPressed: isLoading
126-
? null
127-
: () => context.read<AuthenticationBloc>().add(
153+
onPressed:
154+
isLoading
155+
? null
156+
: () => context.read<AuthenticationBloc>().add(
128157
const AuthenticationGoogleSignInRequested(),
129158
),
130159
// Style adjustments can be made via ElevatedButtonThemeData
131160
),
132161
const SizedBox(height: AppSpacing.lg), // Use constant
133-
134162
// --- Email Sign-In Button ---
135163
ElevatedButton(
136164
// Consider an email icon
137165
// icon: const Icon(Icons.email_outlined),
138-
child: Text(l10n.authenticationEmailSignInButton), // New l10n key needed
139-
onPressed: isLoading
140-
? null
141-
: () {
142-
// Navigate to the dedicated email sign-in page
143-
context.goNamed(Routes.emailSignInName);
144-
},
166+
child: Text(
167+
l10n.authenticationEmailSignInButton,
168+
), // New l10n key needed
169+
onPressed:
170+
isLoading
171+
? null
172+
: () {
173+
// Navigate to the dedicated email sign-in page
174+
context.goNamed(Routes.emailSignInName);
175+
},
145176
),
146177

147178
// --- Anonymous Sign-In Button (Conditional) ---
148179
if (showAnonymousButton) ...[
149180
const SizedBox(height: AppSpacing.lg), // Use constant
150181
OutlinedButton(
151182
child: Text(l10n.authenticationAnonymousSignInButton),
152-
onPressed: isLoading
153-
? null
154-
: () => context.read<AuthenticationBloc>().add(
183+
onPressed:
184+
isLoading
185+
? null
186+
: () => context.read<AuthenticationBloc>().add(
155187
const AuthenticationAnonymousSignInRequested(),
156188
),
157189
),
@@ -160,9 +192,9 @@ class _AuthenticationView extends StatelessWidget {
160192
// --- Loading Indicator (Optional, for general loading state) ---
161193
// If needed, show a general loading indicator when state is AuthenticationLoading
162194
if (isLoading && state is! AuthenticationLinkSending) ...[
163-
const SizedBox(height: AppSpacing.xl),
164-
const Center(child: CircularProgressIndicator()),
165-
]
195+
const SizedBox(height: AppSpacing.xl),
196+
const Center(child: CircularProgressIndicator()),
197+
],
166198
],
167199
),
168200
),

lib/router/router.dart

Lines changed: 2 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -181,10 +181,10 @@ GoRouter createRouter({required ValueNotifier<AppStatus> authStatusNotifier}) {
181181
headline: headline,
182182
subHeadline: subHeadline,
183183
showAnonymousButton: showAnonymousButton,
184+
isLinkingContext: isLinkingContext, // Pass the flag
184185
);
185186
},
186187
routes: [
187-
// --- New Email Flow Sub-routes ---
188188
GoRoute(
189189
path: Routes.emailSignIn,
190190
name: Routes.emailSignInName,
@@ -195,31 +195,6 @@ GoRouter createRouter({required ValueNotifier<AppStatus> authStatusNotifier}) {
195195
name: Routes.emailLinkSentName,
196196
builder: (context, state) => const EmailLinkSentPage(),
197197
),
198-
// --- Existing Placeholder Sub-routes (Keep or remove as needed) ---
199-
GoRoute(
200-
path: Routes.forgotPassword, // Keep if feature is planned
201-
name: Routes.forgotPasswordName,
202-
builder: (BuildContext context, GoRouterState state) {
203-
// Replace with actual implementation when ready
204-
return const Placeholder(child: Text('Forgot Password Page'));
205-
},
206-
),
207-
GoRoute(
208-
path: Routes.resetPassword, // Keep if feature is planned
209-
name: Routes.resetPasswordName,
210-
builder: (BuildContext context, GoRouterState state) {
211-
// Replace with actual implementation when ready
212-
return const Placeholder(child: Text('Reset Password Page'));
213-
},
214-
),
215-
GoRoute(
216-
path: Routes.confirmEmail, // Keep if feature is planned
217-
name: Routes.confirmEmailName,
218-
builder: (BuildContext context, GoRouterState state) {
219-
// Replace with actual implementation when ready
220-
return const Placeholder(child: Text('Confirm Email Page'));
221-
},
222-
),
223198
],
224199
),
225200
GoRoute(
@@ -255,13 +230,9 @@ GoRouter createRouter({required ValueNotifier<AppStatus> authStatusNotifier}) {
255230
),
256231
// --- Account Sub-Route ---
257232
GoRoute(
258-
path: Routes.account, // Keep account page route
233+
path: Routes.account,
259234
name: Routes.accountName,
260235
builder: (context, state) => const AccountPage(),
261-
// No sub-routes needed here anymore for linking
262-
// routes: [
263-
// // Removed AccountLinkingPage route
264-
// ],
265236
),
266237
],
267238
),

0 commit comments

Comments
 (0)