Skip to content

Commit

Permalink
feat: adds No Internet Connectivity screen
Browse files Browse the repository at this point in the history
  • Loading branch information
am-casper committed Feb 27, 2024
1 parent 95056c5 commit d098978
Show file tree
Hide file tree
Showing 13 changed files with 140 additions and 3 deletions.
1 change: 1 addition & 0 deletions devtools_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
extensions:
2 changes: 1 addition & 1 deletion lib/data/constants/env_config.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
class EnvironmentConfig {
static const String BASE_URL = String.fromEnvironment(
'BASE_URL',
defaultValue: 'https://appetizer.onrender.com',
defaultValue: 'https://faf1-103-37-201-177.ngrok-free.app',
);

static const String OAUTH_CLIENT_ID = String.fromEnvironment(
Expand Down
3 changes: 3 additions & 0 deletions lib/data/core/router/registry/paths.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,7 @@ class AppPathsRegistry {
static const String leavesAndRebate = 'leavesAndRebate';
static const String feedback = 'feedback';
static const String resetPassword = 'resetPassword';

static const String noInternetWrapper = '/noInternetWrapper';
static const String noInternetConnection = 'noInternetConnection';
}
10 changes: 10 additions & 0 deletions lib/data/core/router/registry/routes.dart
Original file line number Diff line number Diff line change
Expand Up @@ -61,5 +61,15 @@ class AppRoutesRegistry {
),
],
),
CustomRoute(
path: AppPathsRegistry.noInternetWrapper,
page: NoInternetWrapper.page,
children: [
CustomRoute(
initial: true,
path: AppPathsRegistry.noInternetConnection,
page: NoInternetRoute.page,
),
]),
];
}
2 changes: 2 additions & 0 deletions lib/presentation/app/app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ class _AppetizerAppState extends State<AppetizerApp> {
return [const LoginWrapper()];
case NavigateTo.showHomeScreen:
return [const HomeWrapper()];
case NavigateTo.showNoInternetScreen:
return [const NoInternetWrapper()];
default:
return [];
}
Expand Down
14 changes: 12 additions & 2 deletions lib/presentation/app/bloc/app_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class AppBloc extends Bloc<AppEvent, AppState> {
on<GetUser>(_onGetUser);
on<NavigateToHomeScreen>(_onNavigateToHome);
on<NavigateToLoginScreen>(_onNavigateToLogin);
on<NavigateToNoInternetScreen>(_onNavigateToNoInternetScreen);
on<ToggleCheckOutStatusEvent>(_onToggleCheckOutStatus);
}

Expand Down Expand Up @@ -64,8 +65,12 @@ class AppBloc extends Bloc<AppEvent, AppState> {
emit(state.copyWith(user: user));
add(const NavigateToHomeScreen());
} catch (err) {
LocalStorageService.setValue(key: AppConstants.LOGGED_IN, value: false);
add(const NavigateToLoginScreen());
if (LocalStorageService.getValue<bool>(AppConstants.LOGGED_IN) ?? false) {
add(const NavigateToNoInternetScreen());
} else {
LocalStorageService.setValue(key: AppConstants.LOGGED_IN, value: false);
add(const NavigateToLoginScreen());
}
}
}

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

FutureOr<void> _onNavigateToNoInternetScreen(
NavigateToNoInternetScreen event, Emitter<AppState> emit) {
emit(state.copyWith(navigateTo: NavigateTo.showNoInternetScreen));
}

String get userName => _user?.name ?? 'A';
}
4 changes: 4 additions & 0 deletions lib/presentation/app/bloc/app_event.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ class NavigateToLoginScreen extends AppEvent {
const NavigateToLoginScreen();
}

class NavigateToNoInternetScreen extends AppEvent {
const NavigateToNoInternetScreen();
}

class ToggleCheckOutStatusEvent extends AppEvent {
const ToggleCheckOutStatusEvent();
}
1 change: 1 addition & 0 deletions lib/presentation/app/bloc/app_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ enum NavigateTo {
inital,
showLoginScreen,
showHomeScreen,
showNoInternetScreen,
}

class AppState {
Expand Down
22 changes: 22 additions & 0 deletions lib/presentation/no_internet/bloc/no_internet_bloc.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import 'package:appetizer/domain/models/user/user.dart';
import 'package:appetizer/domain/repositories/user/user_repository.dart';
import 'package:bloc/bloc.dart';
import 'package:equatable/equatable.dart';

part 'no_internet_event.dart';
part 'no_internet_state.dart';

class NoInternetBloc extends Bloc<NoInternetEvent, NoInternetState> {
final UserRepository repo;
NoInternetBloc({required this.repo}) : super(const NoInternetState()) {
on<ReloadPressed>(_onReloadPressed);
}

void _onReloadPressed(
ReloadPressed event, Emitter<NoInternetState> emit) async {
try {
User user = await repo.getCurrentUser();

} catch (e) {}
}
}
12 changes: 12 additions & 0 deletions lib/presentation/no_internet/bloc/no_internet_event.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
part of 'no_internet_bloc.dart';

class NoInternetEvent extends Equatable {
const NoInternetEvent();

@override
List<Object?> get props => [];
}

class ReloadPressed extends NoInternetEvent {
const ReloadPressed();
}
9 changes: 9 additions & 0 deletions lib/presentation/no_internet/bloc/no_internet_state.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
part of 'no_internet_bloc.dart';

class NoInternetState extends Equatable {
const NoInternetState();

@override
List<Object> get props => [];
}

31 changes: 31 additions & 0 deletions lib/presentation/no_internet/components/no_internet_banner.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import 'package:appetizer/data/core/theme/dimensional/dimensional.dart';
import 'package:appetizer/presentation/components/app_banner.dart';
import 'package:flutter/material.dart';
import 'package:google_fonts/google_fonts.dart';

class NoInternetBanner extends StatelessWidget {
const NoInternetBanner({super.key});

@override
Widget build(BuildContext context) {
return AppBanner(
height: 140.toAutoScaledHeight,
child: Row(
children: [
SizedBox(
width: 12.toAutoScaledWidth,
),
Text(
'Appetizer',
style: GoogleFonts.notoSans(
color: Colors.white,
fontSize: 24.toAutoScaledWidth,
fontWeight: FontWeight.w700,
decoration: TextDecoration.none,
),
),
],
),
);
}
}
32 changes: 32 additions & 0 deletions lib/presentation/no_internet/no_internet.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import 'package:appetizer/presentation/components/no_data_found_container.dart';
import 'package:appetizer/presentation/no_internet/components/no_internet_banner.dart';
import 'package:auto_route/auto_route.dart';
import 'package:flutter/material.dart';

@RoutePage()
class NoInternetWrapper extends StatelessWidget {
const NoInternetWrapper({super.key});

@override
Widget build(BuildContext context) {
return const AutoRouter();
}
}

@RoutePage()
class NoInternetScreen extends StatelessWidget {
const NoInternetScreen({super.key});

@override
Widget build(BuildContext context) {
return Container(
color: Colors.white,
child: const Column(
children: [
NoInternetBanner(),
NoDataFoundContainer(title: "No Internet Connection"),
],
),
);
}
}

0 comments on commit d098978

Please sign in to comment.