From fb0f708a540f545e7a329305a3311541011079fc Mon Sep 17 00:00:00 2001 From: John Martel Date: Thu, 25 Apr 2024 07:43:01 -0400 Subject: [PATCH] fix(graphql_flutter): upgrade dependency `connectivity_plus` --- .../lib/src/widgets/hooks/subscription.dart | 32 ++++++++----------- packages/graphql_flutter/pubspec.yaml | 2 +- 2 files changed, 14 insertions(+), 20 deletions(-) diff --git a/packages/graphql_flutter/lib/src/widgets/hooks/subscription.dart b/packages/graphql_flutter/lib/src/widgets/hooks/subscription.dart index 9a140b429..b8318d430 100644 --- a/packages/graphql_flutter/lib/src/widgets/hooks/subscription.dart +++ b/packages/graphql_flutter/lib/src/widgets/hooks/subscription.dart @@ -12,8 +12,7 @@ typedef OnSubscriptionResult = void Function( GraphQLClient? client, ); -typedef SubscriptionBuilder = Widget Function( - QueryResult result); +typedef SubscriptionBuilder = Widget Function(QueryResult result); QueryResult useSubscription( SubscriptionOptions options, { @@ -59,18 +58,16 @@ class _SubscriptionHook extends Hook>> { required this.onSubscriptionResult, }); @override - HookState>, Hook>>> - createState() { + HookState>, Hook>>> createState() { return _SubscriptionHookState(); } } -class _SubscriptionHookState extends HookState< - Stream>, _SubscriptionHook> { +class _SubscriptionHookState extends HookState>, _SubscriptionHook> { late Stream> stream; - ConnectivityResult? _currentConnectivityResult; - StreamSubscription? _networkSubscription; + List _currentConnectivityResult = [ConnectivityResult.none]; + StreamSubscription>? _networkSubscription; void _initSubscription() { final client = hook.client; @@ -88,8 +85,7 @@ class _SubscriptionHookState extends HookState< void initHook() { super.initHook(); _initSubscription(); - _networkSubscription = - Connectivity().onConnectivityChanged.listen(_onNetworkChange); + _networkSubscription = Connectivity().onConnectivityChanged.listen(_onNetworkChange); } @override @@ -107,31 +103,29 @@ class _SubscriptionHookState extends HookState< super.dispose(); } - Future _onNetworkChange(ConnectivityResult result) async { + Future _onNetworkChange(List results) async { //if from offline to online - if (_currentConnectivityResult == ConnectivityResult.none && - (result == ConnectivityResult.mobile || - result == ConnectivityResult.wifi)) { - _currentConnectivityResult = result; + if (_currentConnectivityResult.contains(ConnectivityResult.none) && + (results.contains(ConnectivityResult.mobile) || results.contains(ConnectivityResult.wifi))) { + _currentConnectivityResult = List.from(results, growable: false); // android connectivitystate cannot be trusted // validate with nslookup if (Platform.isAndroid) { try { final nsLookupResult = await InternetAddress.lookup('google.com'); - if (nsLookupResult.isNotEmpty && - nsLookupResult[0].rawAddress.isNotEmpty) { + if (nsLookupResult.isNotEmpty && nsLookupResult[0].rawAddress.isNotEmpty) { _initSubscription(); } // on exception -> no real connection, set current state to none } on SocketException catch (_) { - _currentConnectivityResult = ConnectivityResult.none; + _currentConnectivityResult = [ConnectivityResult.none]; } } else { _initSubscription(); } } else { - _currentConnectivityResult = result; + _currentConnectivityResult = List.from(results, growable: false); } } diff --git a/packages/graphql_flutter/pubspec.yaml b/packages/graphql_flutter/pubspec.yaml index 1483a0183..301853361 100644 --- a/packages/graphql_flutter/pubspec.yaml +++ b/packages/graphql_flutter/pubspec.yaml @@ -15,7 +15,7 @@ dependencies: meta: ^1.7.0 path_provider: ^2.0.1 path: ^1.8.0 - connectivity_plus: ^5.0.0 + connectivity_plus: ^6.0.1 hive: ^2.0.0 plugin_platform_interface: ^2.0.0 flutter_hooks: '>=0.18.2 <0.21.0'