Skip to content

Commit

Permalink
v1.3.1
Browse files Browse the repository at this point in the history
  • Loading branch information
MAlazhariy authored Aug 29, 2024
2 parents fa83792 + 6c2d573 commit d5f5c36
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .flutter-plugins-dependencies
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"connectivity_plus","path":"/Users/malazhariy/.pub-cache/hosted/pub.dev/connectivity_plus-6.0.5/","shared_darwin_source":true,"native_build":true,"dependencies":[]}],"android":[{"name":"connectivity_plus","path":"/Users/malazhariy/.pub-cache/hosted/pub.dev/connectivity_plus-6.0.5/","native_build":true,"dependencies":[]}],"macos":[{"name":"connectivity_plus","path":"/Users/malazhariy/.pub-cache/hosted/pub.dev/connectivity_plus-6.0.5/","shared_darwin_source":true,"native_build":true,"dependencies":[]}],"linux":[{"name":"connectivity_plus","path":"/Users/malazhariy/.pub-cache/hosted/pub.dev/connectivity_plus-6.0.5/","native_build":false,"dependencies":[]}],"windows":[{"name":"connectivity_plus","path":"/Users/malazhariy/.pub-cache/hosted/pub.dev/connectivity_plus-6.0.5/","native_build":true,"dependencies":[]}],"web":[{"name":"connectivity_plus","path":"/Users/malazhariy/.pub-cache/hosted/pub.dev/connectivity_plus-6.0.5/","dependencies":[]}]},"dependencyGraph":[{"name":"connectivity_plus","dependencies":[]}],"date_created":"2024-08-24 14:36:07.069101","version":"3.24.0","swift_package_manager_enabled":false}
{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"connectivity_plus","path":"/Users/malazhariy/.pub-cache/hosted/pub.dev/connectivity_plus-6.0.5/","shared_darwin_source":true,"native_build":true,"dependencies":[]}],"android":[{"name":"connectivity_plus","path":"/Users/malazhariy/.pub-cache/hosted/pub.dev/connectivity_plus-6.0.5/","native_build":true,"dependencies":[]}],"macos":[{"name":"connectivity_plus","path":"/Users/malazhariy/.pub-cache/hosted/pub.dev/connectivity_plus-6.0.5/","shared_darwin_source":true,"native_build":true,"dependencies":[]}],"linux":[{"name":"connectivity_plus","path":"/Users/malazhariy/.pub-cache/hosted/pub.dev/connectivity_plus-6.0.5/","native_build":false,"dependencies":[]}],"windows":[{"name":"connectivity_plus","path":"/Users/malazhariy/.pub-cache/hosted/pub.dev/connectivity_plus-6.0.5/","native_build":true,"dependencies":[]}],"web":[{"name":"connectivity_plus","path":"/Users/malazhariy/.pub-cache/hosted/pub.dev/connectivity_plus-6.0.5/","dependencies":[]}]},"dependencyGraph":[{"name":"connectivity_plus","dependencies":[]}],"date_created":"2024-08-29 12:24:56.307434","version":"3.24.0","swift_package_manager_enabled":false}
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
## [1.3.1]

### Added
- `internetStateStream` accessed from `context` to listen for internet connection changes only (**without listening to loading states**), i.e: `context.internetStateStream.listen((status){})`.

### Fixed
- ios 12+ known issue with `ConnectivityPlus` that get none even if the local network is available,
the bloc is now check the real internet connection on `ios` **even if the local network is none**.

---

## [1.2.0]

### Enhancements
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Add the package to your `pubspec.yaml` under `dependencies:`:
internet_state_manager:
git:
url: https://github.com/MAlazhariy/internet_state_manager.git
ref: v1.2.0
ref: v1.3.1
```
#### Android Configuration
Expand Down
1 change: 1 addition & 0 deletions lib/internet_state_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ export 'src/widgets/internet_state_manager_widget.dart';
export 'src/utils/internet_state_options.dart';
export 'src/internet_state_manager_app.dart';
export 'src/utils/enums/internet_state_enum.dart';
export 'src/utils/extensions/context_extension.dart';


35 changes: 27 additions & 8 deletions lib/src/bloc/internet_manager_cubit.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'dart:async';
import 'dart:io';

import 'package:bloc/bloc.dart';
import 'package:connectivity_plus/connectivity_plus.dart';
Expand All @@ -19,6 +20,15 @@ class InternetManagerCubit extends Cubit<InternetManagerState> {
List<ConnectivityResult> _localConnectionResult = [];
late final StreamSubscription<List<ConnectivityResult>> _localNetworkSubscription;
final _internetConnectionChecker = InternetConnectionChecker.createInstance();
final _internetStreamController = StreamController<InternetState>.broadcast();

/// Stream to listen for internet connection changes.
///
/// You can use this stream logic directly on your code to listen to
/// internet connection changes only (**without listening to loading states**)
Stream<InternetState> get internetStateStream async* {
yield* _internetStreamController.stream;
}

Timer? _timer;

Expand All @@ -32,8 +42,10 @@ class InternetManagerCubit extends Cubit<InternetManagerState> {

/// Return [TRUE] if the device disconnected to any local network
/// i.e: **wifi** or **mobile data**.
bool get disconnectedToLocalNetwork =>
state.status.isInitialized && (_localConnectionResult.isEmpty || _localConnectionResult.contains(ConnectivityResult.none));
bool get disconnectedToLocalNetwork => state.status.isInitialized && _connectivityDisconnected;

bool get _connectivityDisconnected =>
_localConnectionResult.isEmpty || (_localConnectionResult.contains(ConnectivityResult.none) && !Platform.isIOS);

Future<void> _initCheckLocalNetworkConnection() async {
// start stream on local network connection
Expand All @@ -47,7 +59,6 @@ class InternetManagerCubit extends Cubit<InternetManagerState> {
});
}


Future<void> checkConnection() async {
if (_loading) return;
_timer?.cancel();
Expand All @@ -66,14 +77,15 @@ class InternetManagerCubit extends Cubit<InternetManagerState> {
}

// update state if the result changed
if (result != state.status.isConnected) {
if (result != state.status.isConnected && state.status.isInitialized) {
_connectionChanged = true;
_internetStreamController.add(_getStateFromBool(result));
} else if (!state.status.isInitialized) {
_internetStreamController.add(_getStateFromBool(result));
}

emit(
state._setState(
result ? InternetState.connected : InternetState.disconnected,
),
state._setState(_getStateFromBool(result)),
);

if (getOptions.showLogs) {
Expand All @@ -98,10 +110,17 @@ class InternetManagerCubit extends Cubit<InternetManagerState> {

void onRestoreInternetConnectionCalled() => _connectionChanged = false;

InternetState _getStateFromBool(bool result) {
return result ? InternetState.connected : InternetState.disconnected;
}

@override
Future<void> close() async {
_timer?.cancel();
await _localNetworkSubscription.cancel();
await Future.wait([
_localNetworkSubscription.cancel(),
_internetStreamController.close(),
]);
return super.close();
}
}
7 changes: 7 additions & 0 deletions lib/src/utils/extensions/context_extension.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,11 @@ extension ConncectionStatus on BuildContext {
InternetState get internetState => read<InternetManagerCubit>().state.status;
bool get isLoading => read<InternetManagerCubit>().state.loading;
bool get isConnectionRestored => read<InternetManagerCubit>().connectionRestored;

/// Stream to listen for internet connection changes.
///
/// You can use this stream logic directly on your code to listen to
/// internet connection changes only (**without listening to loading states**)
Stream<InternetState> get internetStateStream => read<InternetManagerCubit>().internetStateStream;
}
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ description: A Flutter package for seamless internet connection management. Auto
author: MAlazhariy
homepage: https://github.com/MAlazhariy/internet_state_manager
issue_tracker: https://github.com/MAlazhariy/internet_state_manager/issues
version: 1.2.0
version: 1.3.1

environment:
sdk: '>=3.1.2 <4.0.0'
Expand Down

0 comments on commit d5f5c36

Please sign in to comment.