Skip to content

Commit

Permalink
Merge branch 'main' into casper/feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
A-Kashif108 committed Apr 13, 2024
2 parents 7cf99af + 19bc848 commit 5e9f2ca
Show file tree
Hide file tree
Showing 12 changed files with 224 additions and 2 deletions.
1 change: 1 addition & 0 deletions devtools_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
extensions:
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
24 changes: 24 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,24 @@
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 NoInternetInitial()) {
on<ReloadPressed>(_onReloadPressed);
}

void _onReloadPressed(
ReloadPressed event, Emitter<NoInternetState> emit) async {
emit(const Loading());
try {
await repo.getCurrentUser();
emit(const ReloadSuccess());
} catch (e) {
emit(const NoInternetInitial());
}
}
}
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();
}
20 changes: 20 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,20 @@
part of 'no_internet_bloc.dart';

class NoInternetState extends Equatable {
const NoInternetState();

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

class NoInternetInitial extends NoInternetState {
const NoInternetInitial();
}

class Loading extends NoInternetState {
const Loading();
}

class ReloadSuccess extends NoInternetState {
const ReloadSuccess();
}
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,
),
),
],
),
);
}
}
104 changes: 104 additions & 0 deletions lib/presentation/no_internet/no_internet.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
import 'package:appetizer/app_theme.dart';
import 'package:appetizer/data/core/theme/dimensional/dimensional.dart';
import 'package:appetizer/domain/repositories/user/user_repository.dart';
import 'package:appetizer/presentation/app/bloc/app_bloc.dart';
import 'package:appetizer/presentation/components/loading_indicator.dart';
import 'package:appetizer/presentation/components/no_data_found_container.dart';
import 'package:appetizer/presentation/no_internet/bloc/no_internet_bloc.dart';
import 'package:appetizer/presentation/no_internet/components/no_internet_banner.dart';
import 'package:auto_route/auto_route.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.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 BlocProvider(
create: (context) =>
NoInternetBloc(repo: context.read<UserRepository>()),
child: Container(
color: Colors.white,
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
const NoInternetBanner(),
BlocBuilder<NoInternetBloc, NoInternetState>(
builder: (context, state) {
if (state is ReloadSuccess) {
context.read<AppBloc>().add(const GetUser());
}
if (state is NoInternetInitial) {
return Column(
children: [
const NoDataFoundContainer(
title: "No Internet Connectivity!"),
SizedBox(
height: 20.toAutoScaledHeight,
),
GestureDetector(
onTap: () => context
.read<NoInternetBloc>()
.add(const ReloadPressed()),
child: Container(
height: 24.toAutoScaledHeight,
width: 72.toAutoScaledWidth,
padding: EdgeInsets.symmetric(
horizontal: 8.toAutoScaledWidth,
),
decoration: ShapeDecoration(
color: AppTheme.primary,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(6)),
),
child: Center(
child: Text(
'Reload',
style: AppTheme.bodyText1.copyWith(
color: AppTheme.white,
fontSize: 14.toAutoScaledFont,
fontWeight: FontWeight.w600,
decoration: TextDecoration.none),
),
),
)),
],
);
}
return SizedBox(
height: 200.toAutoScaledHeight,
child: const Align(
alignment: Alignment.bottomCenter,
child: LoadingIndicator(),
),
);
}),
SizedBox(
height: 100.toAutoScaledHeight,
)
],
),
));
}
}
// Container(
// color: Colors.white,
// child: const Column(
// children: [
// NoInternetBanner(),
// NoDataFoundContainer(title: "No Internet Connection"),
// ],
// ),
// ),

0 comments on commit 5e9f2ca

Please sign in to comment.