Skip to content

Commit d639bb7

Browse files
committed
refactor: moved the sign-in and logout button within the user header, displayed conditionally based on authentication status, and built using dedicated private methods.
1 parent c368da7 commit d639bb7

File tree

3 files changed

+56
-72
lines changed

3 files changed

+56
-72
lines changed

lib/account/view/account_page.dart

Lines changed: 48 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import 'package:ht_main/account/bloc/account_bloc.dart';
77
import 'package:ht_main/app/bloc/app_bloc.dart';
88
import 'package:ht_main/l10n/l10n.dart';
99
import 'package:ht_main/router/routes.dart';
10+
import 'package:ht_main/shared/constants/app_spacing.dart';
1011

1112
/// {@template account_page}
1213
/// Page widget for the Account feature.
@@ -54,20 +55,15 @@ class _AccountView extends StatelessWidget {
5455
appBar: AppBar(title: Text(l10n.accountPageTitle)),
5556
body: ListView(
5657
// Use ListView for potential scrolling if content grows
57-
padding: const EdgeInsets.all(16),
58+
padding: const EdgeInsets.all(AppSpacing.lg), // Use AppSpacing
5859
children: [
5960
// --- User Header ---
6061
_buildUserHeader(context, user, isAnonymous),
61-
const SizedBox(height: 24),
62-
62+
const SizedBox(height: AppSpacing.xl), // Use AppSpacing
6363
// --- Action Tiles ---
64+
// Settings Tile is now the first actionable item below the header
6465
_buildSettingsTile(context),
65-
const Divider(),
66-
if (isAnonymous)
67-
_buildBackupTile(context) // Show Backup CTA for anonymous
68-
else
69-
_buildLogoutTile(context), // Show Logout for authenticated
70-
const Divider(),
66+
const Divider(), // Divider after settings
7167
],
7268
),
7369
);
@@ -99,89 +95,74 @@ class _AccountView extends StatelessWidget {
9995
)
10096
: null,
10197
),
102-
const SizedBox(height: 16),
98+
const SizedBox(height: AppSpacing.lg), // Use AppSpacing
10399
Text(
104100
isAnonymous
105101
? l10n.accountAnonymousUser
106102
: user.displayName ?? l10n.accountNoNameUser,
107103
style: textTheme.titleLarge,
108104
textAlign: TextAlign.center,
109105
),
110-
const SizedBox(height: 4),
111-
Text(
112-
// Convert enum to user-friendly string
113-
_authenticationStatusToString(context, user.authenticationStatus),
114-
style: textTheme.bodyMedium?.copyWith(
115-
color: theme.colorScheme.secondary,
116-
),
117-
textAlign: TextAlign.center,
118-
),
106+
// Conditionally display Sign In or Logout button
107+
if (isAnonymous)
108+
_buildSignInButton(context)
109+
else
110+
_buildLogoutButton(context),
119111
],
120112
);
121113
}
122114

123-
/// Builds the ListTile for navigating to Settings.
124-
Widget _buildSettingsTile(BuildContext context) {
115+
/// Builds the sign-in button for anonymous users.
116+
Widget _buildSignInButton(BuildContext context) {
125117
final l10n = context.l10n;
126-
return ListTile(
127-
leading: const Icon(Icons.settings_outlined),
128-
title: Text(l10n.accountSettingsTile),
129-
trailing: const Icon(Icons.chevron_right),
130-
onTap: () {
131-
// Navigate to the existing settings route
132-
context.goNamed(Routes.settingsName);
133-
},
118+
return Padding(
119+
padding: const EdgeInsets.only(top: AppSpacing.sm),
120+
child: TextButton(
121+
onPressed: () {
122+
// Navigate to the authentication page in linking mode
123+
context.goNamed(
124+
Routes.authenticationName,
125+
queryParameters: {'context': 'linking'},
126+
);
127+
},
128+
child: Text(l10n.accountSignInPromptButton),
129+
),
134130
);
135131
}
136132

137-
/// Builds the ListTile for logging out (for authenticated users).
138-
Widget _buildLogoutTile(BuildContext context) {
133+
/// Builds the logout button for authenticated users.
134+
Widget _buildLogoutButton(BuildContext context) {
139135
final l10n = context.l10n;
140-
return ListTile(
141-
leading: Icon(Icons.logout, color: Theme.of(context).colorScheme.error),
142-
title: Text(
143-
l10n.accountSignOutTile,
144-
style: TextStyle(color: Theme.of(context).colorScheme.error),
136+
final theme = Theme.of(context);
137+
return Padding(
138+
padding: const EdgeInsets.only(top: AppSpacing.sm),
139+
child: OutlinedButton(
140+
style: OutlinedButton.styleFrom(
141+
foregroundColor: theme.colorScheme.error,
142+
side: BorderSide(color: theme.colorScheme.error),
143+
),
144+
onPressed: () {
145+
context.read<AccountBloc>().add(const AccountLogoutRequested());
146+
// Global redirect will be handled by AppBloc/GoRouter
147+
},
148+
// Assuming l10n.accountSignOutButton exists or will be added
149+
// Reusing existing tile text for now as button text might differ
150+
child: Text(l10n.accountSignOutTile),
145151
),
146-
onTap: () {
147-
context.read<AccountBloc>().add(const AccountLogoutRequested());
148-
// Global redirect will be handled by AppBloc/GoRouter
149-
},
150152
);
151153
}
152154

153-
/// Builds the ListTile prompting anonymous users to sign in/connect.
154-
Widget _buildBackupTile(BuildContext context) {
155+
/// Builds the ListTile for navigating to Settings.
156+
Widget _buildSettingsTile(BuildContext context) {
155157
final l10n = context.l10n;
156158
return ListTile(
157-
leading: const Icon(Icons.link),
158-
title: Text(l10n.accountConnectPrompt),
159-
subtitle: Text(l10n.accountConnectBenefit),
160-
isThreeLine: true, // Allow more space for subtitle
159+
leading: const Icon(Icons.settings_outlined),
160+
title: Text(l10n.accountSettingsTile),
161161
trailing: const Icon(Icons.chevron_right),
162162
onTap: () {
163-
// Navigate to the authentication page in linking mode
164-
context.goNamed(
165-
Routes.authenticationName,
166-
queryParameters: {'context': 'linking'},
167-
);
163+
// Navigate to the existing settings route
164+
context.goNamed(Routes.settingsName);
168165
},
169166
);
170167
}
171-
172-
/// Helper to convert AuthenticationStatus enum to a display string.
173-
String _authenticationStatusToString(
174-
BuildContext context,
175-
AuthenticationStatus status,
176-
) {
177-
final l10n = context.l10n;
178-
switch (status) {
179-
case AuthenticationStatus.authenticated:
180-
return l10n.accountStatusAuthenticated;
181-
case AuthenticationStatus.anonymous:
182-
return l10n.accountStatusAnonymous;
183-
case AuthenticationStatus.unauthenticated:
184-
return l10n.accountStatusUnauthenticated;
185-
}
186-
}
187168
}

lib/app/view/app.dart

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,18 @@
22
// ignore_for_file: deprecated_member_use
33

44
import 'dart:async';
5-
import 'package:firebase_dynamic_links/firebase_dynamic_links.dart';
5+
import 'package:firebase_dynamic_links/firebase_dynamic_links.dart';
66
import 'package:flutter/material.dart';
77
import 'package:flutter_bloc/flutter_bloc.dart';
88
import 'package:go_router/go_router.dart';
99
import 'package:ht_authentication_repository/ht_authentication_repository.dart';
1010
import 'package:ht_headlines_repository/ht_headlines_repository.dart';
11-
import 'package:ht_kv_storage_service/ht_kv_storage_service.dart';
11+
import 'package:ht_kv_storage_service/ht_kv_storage_service.dart';
1212
import 'package:ht_main/app/bloc/app_bloc.dart';
13-
import 'package:ht_main/authentication/bloc/authentication_bloc.dart';
13+
import 'package:ht_main/authentication/bloc/authentication_bloc.dart';
1414
import 'package:ht_main/l10n/l10n.dart';
1515
import 'package:ht_main/router/router.dart';
16-
import 'package:ht_main/shared/theme/app_theme.dart';
16+
import 'package:ht_main/shared/theme/app_theme.dart';
1717

1818
class App extends StatelessWidget {
1919
const App({
@@ -94,7 +94,6 @@ class _AppViewState extends State<_AppView> {
9494
super.dispose();
9595
}
9696

97-
9897
/// Initializes Firebase Dynamic Links listeners.
9998
Future<void> _initDynamicLinks() async {
10099
// Handle links received while the app is running

lib/l10n/arb/app_en.arb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,5 +283,9 @@
283283
"notificationsTooltip": "View notifications",
284284
"@notificationsTooltip": {
285285
"description": "Tooltip text for the notifications icon button in the feed page AppBar"
286+
},
287+
"accountSignInPromptButton": "Sign Up / Sign In",
288+
"@accountSignInPromptButton": {
289+
"description": "Button text shown in the user header for anonymous users to initiate sign-in/sign-up"
286290
}
287291
}

0 commit comments

Comments
 (0)