Skip to content

Commit bd710d1

Browse files
committed
feat(authentication): refactor request code page to use localized errors
Updates the `RequestCodePage` to use the `toFriendlyMessage` extension from `ht_ui_kit`. The `BlocConsumer` now accesses the `exception` object from the `AuthenticationState` and passes it to the extension method to display a user-friendly, localized error message in the `SnackBar`. The `buildWhen` condition is also updated to react to changes in the `exception` field.
1 parent 99ef00e commit bd710d1

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

lib/authentication/view/request_code_page.dart

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import 'package:ht_dashboard/authentication/bloc/authentication_bloc.dart';
1010
import 'package:ht_dashboard/l10n/l10n.dart';
1111
import 'package:ht_dashboard/router/routes.dart';
1212
import 'package:ht_dashboard/shared/constants/app_spacing.dart';
13+
import 'package:ht_ui_kit/ht_ui_kit.dart';
1314

1415
/// {@template request_code_page}
1516
/// Page for initiating the email code sign-in process.
@@ -70,12 +71,13 @@ class _RequestCodeView extends StatelessWidget {
7071
body: SafeArea(
7172
child: BlocConsumer<AuthenticationBloc, AuthenticationState>(
7273
listener: (context, state) {
73-
if (state.status == AuthenticationStatus.failure) {
74+
if (state.status == AuthenticationStatus.failure &&
75+
state.exception != null) {
7476
ScaffoldMessenger.of(context)
7577
..hideCurrentSnackBar()
7678
..showSnackBar(
7779
SnackBar(
78-
content: Text(state.errorMessage!),
80+
content: Text(state.exception!.toFriendlyMessage(context)),
7981
backgroundColor: colorScheme.error,
8082
),
8183
);
@@ -92,7 +94,7 @@ class _RequestCodeView extends StatelessWidget {
9294
// BuildWhen prevents unnecessary rebuilds if only listening
9395
buildWhen: (previous, current) =>
9496
previous.status != current.status ||
95-
previous.errorMessage != current.errorMessage ||
97+
previous.exception != current.exception ||
9698
previous.email != current.email,
9799
builder: (context, state) {
98100
final isLoading =

0 commit comments

Comments
 (0)