Skip to content

Commit acd9a92

Browse files
authored
Merge branch 'main' into casper/hostel_change
2 parents 2dc9e43 + 19bc848 commit acd9a92

File tree

12 files changed

+224
-2
lines changed

12 files changed

+224
-2
lines changed

devtools_options.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
extensions:

lib/data/core/router/registry/paths.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,7 @@ class AppPathsRegistry {
1818
static const String feedback = 'feedback';
1919
static const String hostelChange = 'hostelChange';
2020
static const String resetPassword = 'resetPassword';
21+
22+
static const String noInternetWrapper = '/noInternetWrapper';
23+
static const String noInternetConnection = 'noInternetConnection';
2124
}

lib/data/core/router/registry/routes.dart

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,5 +65,15 @@ class AppRoutesRegistry {
6565
),
6666
],
6767
),
68+
CustomRoute(
69+
path: AppPathsRegistry.noInternetWrapper,
70+
page: NoInternetWrapper.page,
71+
children: [
72+
CustomRoute(
73+
initial: true,
74+
path: AppPathsRegistry.noInternetConnection,
75+
page: NoInternetRoute.page,
76+
),
77+
]),
6878
];
6979
}

lib/presentation/app/app.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ class _AppetizerAppState extends State<AppetizerApp> {
4646
return [const LoginWrapper()];
4747
case NavigateTo.showHomeScreen:
4848
return [const HomeWrapper()];
49+
case NavigateTo.showNoInternetScreen:
50+
return [const NoInternetWrapper()];
4951
default:
5052
return [];
5153
}

lib/presentation/app/bloc/app_bloc.dart

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ class AppBloc extends Bloc<AppEvent, AppState> {
2525
on<GetUser>(_onGetUser);
2626
on<NavigateToHomeScreen>(_onNavigateToHome);
2727
on<NavigateToLoginScreen>(_onNavigateToLogin);
28+
on<NavigateToNoInternetScreen>(_onNavigateToNoInternetScreen);
2829
on<ToggleCheckOutStatusEvent>(_onToggleCheckOutStatus);
2930
}
3031

@@ -64,8 +65,12 @@ class AppBloc extends Bloc<AppEvent, AppState> {
6465
emit(state.copyWith(user: user));
6566
add(const NavigateToHomeScreen());
6667
} catch (err) {
67-
LocalStorageService.setValue(key: AppConstants.LOGGED_IN, value: false);
68-
add(const NavigateToLoginScreen());
68+
if (LocalStorageService.getValue<bool>(AppConstants.LOGGED_IN) ?? false) {
69+
add(const NavigateToNoInternetScreen());
70+
} else {
71+
LocalStorageService.setValue(key: AppConstants.LOGGED_IN, value: false);
72+
add(const NavigateToLoginScreen());
73+
}
6974
}
7075
}
7176

@@ -81,5 +86,10 @@ class AppBloc extends Bloc<AppEvent, AppState> {
8186
emit(state.copyWith(navigateTo: NavigateTo.showLoginScreen));
8287
}
8388

89+
FutureOr<void> _onNavigateToNoInternetScreen(
90+
NavigateToNoInternetScreen event, Emitter<AppState> emit) {
91+
emit(state.copyWith(navigateTo: NavigateTo.showNoInternetScreen));
92+
}
93+
8494
String get userName => _user?.name ?? 'A';
8595
}

lib/presentation/app/bloc/app_event.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ class NavigateToLoginScreen extends AppEvent {
2323
const NavigateToLoginScreen();
2424
}
2525

26+
class NavigateToNoInternetScreen extends AppEvent {
27+
const NavigateToNoInternetScreen();
28+
}
29+
2630
class ToggleCheckOutStatusEvent extends AppEvent {
2731
const ToggleCheckOutStatusEvent();
2832
}

lib/presentation/app/bloc/app_state.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ enum NavigateTo {
44
inital,
55
showLoginScreen,
66
showHomeScreen,
7+
showNoInternetScreen,
78
}
89

910
class AppState {
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import 'package:appetizer/domain/repositories/user/user_repository.dart';
2+
import 'package:bloc/bloc.dart';
3+
import 'package:equatable/equatable.dart';
4+
5+
part 'no_internet_event.dart';
6+
part 'no_internet_state.dart';
7+
8+
class NoInternetBloc extends Bloc<NoInternetEvent, NoInternetState> {
9+
final UserRepository repo;
10+
NoInternetBloc({required this.repo}) : super(const NoInternetInitial()) {
11+
on<ReloadPressed>(_onReloadPressed);
12+
}
13+
14+
void _onReloadPressed(
15+
ReloadPressed event, Emitter<NoInternetState> emit) async {
16+
emit(const Loading());
17+
try {
18+
await repo.getCurrentUser();
19+
emit(const ReloadSuccess());
20+
} catch (e) {
21+
emit(const NoInternetInitial());
22+
}
23+
}
24+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
part of 'no_internet_bloc.dart';
2+
3+
class NoInternetEvent extends Equatable {
4+
const NoInternetEvent();
5+
6+
@override
7+
List<Object?> get props => [];
8+
}
9+
10+
class ReloadPressed extends NoInternetEvent {
11+
const ReloadPressed();
12+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
part of 'no_internet_bloc.dart';
2+
3+
class NoInternetState extends Equatable {
4+
const NoInternetState();
5+
6+
@override
7+
List<Object> get props => [];
8+
}
9+
10+
class NoInternetInitial extends NoInternetState {
11+
const NoInternetInitial();
12+
}
13+
14+
class Loading extends NoInternetState {
15+
const Loading();
16+
}
17+
18+
class ReloadSuccess extends NoInternetState {
19+
const ReloadSuccess();
20+
}

0 commit comments

Comments
 (0)