-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #281 from mdgspace/casper/hiveIssue
feat: adds a No Internet Connectivity Screen
- Loading branch information
Showing
12 changed files
with
224 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
extensions: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ enum NavigateTo { | |
inital, | ||
showLoginScreen, | ||
showHomeScreen, | ||
showNoInternetScreen, | ||
} | ||
|
||
class AppState { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
31
lib/presentation/no_internet/components/no_internet_banner.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
), | ||
), | ||
], | ||
), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"), | ||
// ], | ||
// ), | ||
// ), |