-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8dbdd10
commit d5b76f3
Showing
18 changed files
with
282 additions
and
54 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export 'logic/cubit.dart'; | ||
export 'logic/debug_bloc.dart'; | ||
export 'logic/input_validators.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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export 'cubit/authentication_cubit.dart'; | ||
export 'cubit/internet_cubit.dart'; | ||
export 'cubit/leaderboard_cubit.dart'; | ||
export 'cubit/quiz_cubit.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,41 @@ | ||
import 'dart:async'; | ||
|
||
import 'package:bloc/bloc.dart'; | ||
import 'package:connectivity_plus/connectivity_plus.dart'; | ||
import 'package:equatable/equatable.dart'; | ||
|
||
part 'internet_state.dart'; | ||
|
||
class InternetCubit extends Cubit<InternetState> { | ||
static InternetCubit? _instance; | ||
|
||
factory InternetCubit() { | ||
return _instance ??= InternetCubit._internal(); | ||
} | ||
|
||
InternetCubit._internal() : super(InternetLoading()); | ||
|
||
StreamSubscription? connectivityStreamSubscription; | ||
|
||
StreamSubscription<List<ConnectivityResult>> monitorInternetConnection() { | ||
final connectivityStream = Connectivity().onConnectivityChanged; | ||
connectivityStreamSubscription?.cancel(); | ||
return connectivityStreamSubscription = connectivityStream.listen( | ||
(connectivityResults) { | ||
connectivityResults.first == ConnectivityResult.none | ||
? sendInternetFailure() | ||
: sendInternetResume(); | ||
}, | ||
); | ||
} | ||
|
||
void sendInternetFailure() => emit(InternetDisconnected()); | ||
|
||
void sendInternetResume() => emit(InternetConnected()); | ||
|
||
@override | ||
Future<void> close() { | ||
connectivityStreamSubscription?.cancel(); | ||
return super.close(); | ||
} | ||
} |
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,14 @@ | ||
part of 'internet_cubit.dart'; | ||
|
||
sealed class InternetState extends Equatable { | ||
const InternetState(); | ||
|
||
@override | ||
List<Object> get props => []; | ||
} | ||
|
||
class InternetLoading extends InternetState {} | ||
|
||
class InternetConnected extends InternetState {} | ||
|
||
class InternetDisconnected extends InternetState {} |
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
Oops, something went wrong.