Skip to content

Commit 736ce0b

Browse files
committed
refactor(authentication): update imports and exceptions
- Update import paths for core, ui_kit, and auth_repository packages - Replace HtAuthRepository with AuthRepository - Replace HtHttpException with HttpException - Simplify emit statements in AuthenticationBloc
1 parent 47971e8 commit 736ce0b

File tree

3 files changed

+39
-136
lines changed

3 files changed

+39
-136
lines changed

lib/authentication/bloc/authentication_bloc.dart

Lines changed: 30 additions & 120 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
import 'dart:async';
22

3+
import 'package:auth_repository/auth_repository.dart';
34
import 'package:bloc/bloc.dart';
4-
import 'package:equatable/equatable.dart';
5-
import 'package:ht_auth_repository/ht_auth_repository.dart';
6-
import 'package:ht_shared/ht_shared.dart'
5+
import 'package:core/core.dart'
76
show
87
AuthenticationException,
98
ForbiddenException,
10-
HtHttpException,
9+
HttpException,
1110
InvalidInputException,
1211
NetworkException,
1312
NotFoundException,
@@ -16,6 +15,7 @@ import 'package:ht_shared/ht_shared.dart'
1615
UnauthorizedException,
1716
UnknownException,
1817
User;
18+
import 'package:equatable/equatable.dart';
1919

2020
part 'authentication_event.dart';
2121
part 'authentication_state.dart';
@@ -26,7 +26,7 @@ part 'authentication_state.dart';
2626
class AuthenticationBloc
2727
extends Bloc<AuthenticationEvent, AuthenticationState> {
2828
/// {@macro authentication_bloc}
29-
AuthenticationBloc({required HtAuthRepository authenticationRepository})
29+
AuthenticationBloc({required AuthRepository authenticationRepository})
3030
: _authenticationRepository = authenticationRepository,
3131
super(const AuthenticationState()) {
3232
// Listen to authentication state changes from the repository
@@ -42,7 +42,7 @@ class AuthenticationBloc
4242
on<AuthenticationSignOutRequested>(_onAuthenticationSignOutRequested);
4343
}
4444

45-
final HtAuthRepository _authenticationRepository;
45+
final AuthRepository _authenticationRepository;
4646
late final StreamSubscription<User?> _userAuthSubscription;
4747

4848
/// Handles [_AuthenticationStatusChanged] events.
@@ -85,55 +85,20 @@ class AuthenticationBloc
8585
),
8686
);
8787
} on InvalidInputException catch (e) {
88-
emit(
89-
state.copyWith(
90-
status: AuthenticationStatus.failure,
91-
exception: e,
92-
),
93-
);
88+
emit(state.copyWith(status: AuthenticationStatus.failure, exception: e));
9489
} on UnauthorizedException catch (e) {
95-
emit(
96-
state.copyWith(
97-
status: AuthenticationStatus.failure,
98-
exception: e,
99-
),
100-
);
90+
emit(state.copyWith(status: AuthenticationStatus.failure, exception: e));
10191
} on ForbiddenException catch (e) {
102-
emit(
103-
state.copyWith(
104-
status: AuthenticationStatus.failure,
105-
exception: e,
106-
),
107-
);
92+
emit(state.copyWith(status: AuthenticationStatus.failure, exception: e));
10893
} on NetworkException catch (e) {
109-
emit(
110-
state.copyWith(
111-
status: AuthenticationStatus.failure,
112-
exception: e,
113-
),
114-
);
94+
emit(state.copyWith(status: AuthenticationStatus.failure, exception: e));
11595
} on ServerException catch (e) {
116-
emit(
117-
state.copyWith(
118-
status: AuthenticationStatus.failure,
119-
exception: e,
120-
),
121-
);
96+
emit(state.copyWith(status: AuthenticationStatus.failure, exception: e));
12297
} on OperationFailedException catch (e) {
123-
emit(
124-
state.copyWith(
125-
status: AuthenticationStatus.failure,
126-
exception: e,
127-
),
128-
);
129-
} on HtHttpException catch (e) {
130-
// Catch any other HtHttpException subtypes
131-
emit(
132-
state.copyWith(
133-
status: AuthenticationStatus.failure,
134-
exception: e,
135-
),
136-
);
98+
emit(state.copyWith(status: AuthenticationStatus.failure, exception: e));
99+
} on HttpException catch (e) {
100+
// Catch any other HttpException subtypes
101+
emit(state.copyWith(status: AuthenticationStatus.failure, exception: e));
137102
} catch (e) {
138103
// Catch any other unexpected errors
139104
emit(
@@ -161,55 +126,20 @@ class AuthenticationBloc
161126
// On success, the _AuthenticationStatusChanged listener will handle
162127
// emitting AuthenticationAuthenticated.
163128
} on InvalidInputException catch (e) {
164-
emit(
165-
state.copyWith(
166-
status: AuthenticationStatus.failure,
167-
exception: e,
168-
),
169-
);
129+
emit(state.copyWith(status: AuthenticationStatus.failure, exception: e));
170130
} on AuthenticationException catch (e) {
171-
emit(
172-
state.copyWith(
173-
status: AuthenticationStatus.failure,
174-
exception: e,
175-
),
176-
);
131+
emit(state.copyWith(status: AuthenticationStatus.failure, exception: e));
177132
} on NotFoundException catch (e) {
178-
emit(
179-
state.copyWith(
180-
status: AuthenticationStatus.failure,
181-
exception: e,
182-
),
183-
);
133+
emit(state.copyWith(status: AuthenticationStatus.failure, exception: e));
184134
} on NetworkException catch (e) {
185-
emit(
186-
state.copyWith(
187-
status: AuthenticationStatus.failure,
188-
exception: e,
189-
),
190-
);
135+
emit(state.copyWith(status: AuthenticationStatus.failure, exception: e));
191136
} on ServerException catch (e) {
192-
emit(
193-
state.copyWith(
194-
status: AuthenticationStatus.failure,
195-
exception: e,
196-
),
197-
);
137+
emit(state.copyWith(status: AuthenticationStatus.failure, exception: e));
198138
} on OperationFailedException catch (e) {
199-
emit(
200-
state.copyWith(
201-
status: AuthenticationStatus.failure,
202-
exception: e,
203-
),
204-
);
205-
} on HtHttpException catch (e) {
206-
// Catch any other HtHttpException subtypes
207-
emit(
208-
state.copyWith(
209-
status: AuthenticationStatus.failure,
210-
exception: e,
211-
),
212-
);
139+
emit(state.copyWith(status: AuthenticationStatus.failure, exception: e));
140+
} on HttpException catch (e) {
141+
// Catch any other HttpException subtypes
142+
emit(state.copyWith(status: AuthenticationStatus.failure, exception: e));
213143
} catch (e) {
214144
// Catch any other unexpected errors
215145
emit(
@@ -233,34 +163,14 @@ class AuthenticationBloc
233163
// On success, the _AuthenticationStatusChanged listener will handle
234164
// emitting AuthenticationUnauthenticated.
235165
} on NetworkException catch (e) {
236-
emit(
237-
state.copyWith(
238-
status: AuthenticationStatus.failure,
239-
exception: e,
240-
),
241-
);
166+
emit(state.copyWith(status: AuthenticationStatus.failure, exception: e));
242167
} on ServerException catch (e) {
243-
emit(
244-
state.copyWith(
245-
status: AuthenticationStatus.failure,
246-
exception: e,
247-
),
248-
);
168+
emit(state.copyWith(status: AuthenticationStatus.failure, exception: e));
249169
} on OperationFailedException catch (e) {
250-
emit(
251-
state.copyWith(
252-
status: AuthenticationStatus.failure,
253-
exception: e,
254-
),
255-
);
256-
} on HtHttpException catch (e) {
257-
// Catch any other HtHttpException subtypes
258-
emit(
259-
state.copyWith(
260-
status: AuthenticationStatus.failure,
261-
exception: e,
262-
),
263-
);
170+
emit(state.copyWith(status: AuthenticationStatus.failure, exception: e));
171+
} on HttpException catch (e) {
172+
// Catch any other HttpException subtypes
173+
emit(state.copyWith(status: AuthenticationStatus.failure, exception: e));
264174
} catch (e) {
265175
emit(
266176
state.copyWith(

lib/authentication/bloc/authentication_state.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ final class AuthenticationState extends Equatable {
4848
final String? email;
4949

5050
/// The error describing an authentication failure, if any.
51-
final HtHttpException? exception;
51+
final HttpException? exception;
5252

5353
@override
5454
List<Object?> get props => [status, user, email, exception];
@@ -59,7 +59,7 @@ final class AuthenticationState extends Equatable {
5959
AuthenticationStatus? status,
6060
User? user,
6161
String? email,
62-
HtHttpException? exception,
62+
HttpException? exception,
6363
}) {
6464
return AuthenticationState(
6565
status: status ?? this.status,

lib/authentication/view/authentication_page.dart

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import 'package:flutter/material.dart';
22
import 'package:flutter_bloc/flutter_bloc.dart';
3+
import 'package:flutter_news_app_web_dashboard_full_source_code/authentication/bloc/authentication_bloc.dart';
4+
import 'package:flutter_news_app_web_dashboard_full_source_code/l10n/l10n.dart';
5+
import 'package:flutter_news_app_web_dashboard_full_source_code/router/routes.dart';
36
import 'package:go_router/go_router.dart';
4-
import 'package:ht_dashboard/authentication/bloc/authentication_bloc.dart';
5-
import 'package:ht_dashboard/l10n/l10n.dart';
6-
import 'package:ht_dashboard/router/routes.dart';
7-
import 'package:ht_ui_kit/ht_ui_kit.dart';
7+
import 'package:ui_kit/ui_kit.dart';
88

99
/// {@template authentication_page}
1010
/// Displays authentication options for the dashboard.
@@ -23,10 +23,7 @@ class AuthenticationPage extends StatelessWidget {
2323
final colorScheme = Theme.of(context).colorScheme;
2424

2525
return Scaffold(
26-
appBar: AppBar(
27-
backgroundColor: Colors.transparent,
28-
elevation: 0,
29-
),
26+
appBar: AppBar(backgroundColor: Colors.transparent, elevation: 0),
3027
body: SafeArea(
3128
child: BlocConsumer<AuthenticationBloc, AuthenticationState>(
3229
// Listener remains crucial for feedback (errors)
@@ -65,9 +62,7 @@ class AuthenticationPage extends StatelessWidget {
6562
children: [
6663
// --- Icon ---
6764
Padding(
68-
padding: const EdgeInsets.only(
69-
bottom: AppSpacing.xl,
70-
),
65+
padding: const EdgeInsets.only(bottom: AppSpacing.xl),
7166
child: Icon(
7267
Icons.newspaper,
7368
size: AppSpacing.xxl * 2,
@@ -98,9 +93,7 @@ class AuthenticationPage extends StatelessWidget {
9893
onPressed: isLoading
9994
? null
10095
: () {
101-
context.goNamed(
102-
Routes.requestCodeName,
103-
);
96+
context.goNamed(Routes.requestCodeName);
10497
},
10598
label: Text(l10n.authenticationEmailSignInButton),
10699
style: ElevatedButton.styleFrom(

0 commit comments

Comments
 (0)