Skip to content

Commit c0621cc

Browse files
Merge pull request #1428 from valian-ca/fix/upgrade-connectivity-plus
fix(graphql_flutter): upgrade dependency `connectivity_plus`
2 parents 6b28b45 + fb0f708 commit c0621cc

File tree

2 files changed

+14
-20
lines changed

2 files changed

+14
-20
lines changed

packages/graphql_flutter/lib/src/widgets/hooks/subscription.dart

+13-19
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@ typedef OnSubscriptionResult<TParsed> = void Function(
1212
GraphQLClient? client,
1313
);
1414

15-
typedef SubscriptionBuilder<TParsed> = Widget Function(
16-
QueryResult<TParsed> result);
15+
typedef SubscriptionBuilder<TParsed> = Widget Function(QueryResult<TParsed> result);
1716

1817
QueryResult<TParsed> useSubscription<TParsed>(
1918
SubscriptionOptions<TParsed> options, {
@@ -59,18 +58,16 @@ class _SubscriptionHook<TParsed> extends Hook<Stream<QueryResult<TParsed>>> {
5958
required this.onSubscriptionResult,
6059
});
6160
@override
62-
HookState<Stream<QueryResult<TParsed>>, Hook<Stream<QueryResult<TParsed>>>>
63-
createState() {
61+
HookState<Stream<QueryResult<TParsed>>, Hook<Stream<QueryResult<TParsed>>>> createState() {
6462
return _SubscriptionHookState();
6563
}
6664
}
6765

68-
class _SubscriptionHookState<TParsed> extends HookState<
69-
Stream<QueryResult<TParsed>>, _SubscriptionHook<TParsed>> {
66+
class _SubscriptionHookState<TParsed> extends HookState<Stream<QueryResult<TParsed>>, _SubscriptionHook<TParsed>> {
7067
late Stream<QueryResult<TParsed>> stream;
7168

72-
ConnectivityResult? _currentConnectivityResult;
73-
StreamSubscription<ConnectivityResult>? _networkSubscription;
69+
List<ConnectivityResult> _currentConnectivityResult = [ConnectivityResult.none];
70+
StreamSubscription<List<ConnectivityResult>>? _networkSubscription;
7471

7572
void _initSubscription() {
7673
final client = hook.client;
@@ -88,8 +85,7 @@ class _SubscriptionHookState<TParsed> extends HookState<
8885
void initHook() {
8986
super.initHook();
9087
_initSubscription();
91-
_networkSubscription =
92-
Connectivity().onConnectivityChanged.listen(_onNetworkChange);
88+
_networkSubscription = Connectivity().onConnectivityChanged.listen(_onNetworkChange);
9389
}
9490

9591
@override
@@ -107,31 +103,29 @@ class _SubscriptionHookState<TParsed> extends HookState<
107103
super.dispose();
108104
}
109105

110-
Future<void> _onNetworkChange(ConnectivityResult result) async {
106+
Future<void> _onNetworkChange(List<ConnectivityResult> results) async {
111107
//if from offline to online
112-
if (_currentConnectivityResult == ConnectivityResult.none &&
113-
(result == ConnectivityResult.mobile ||
114-
result == ConnectivityResult.wifi)) {
115-
_currentConnectivityResult = result;
108+
if (_currentConnectivityResult.contains(ConnectivityResult.none) &&
109+
(results.contains(ConnectivityResult.mobile) || results.contains(ConnectivityResult.wifi))) {
110+
_currentConnectivityResult = List.from(results, growable: false);
116111

117112
// android connectivitystate cannot be trusted
118113
// validate with nslookup
119114
if (Platform.isAndroid) {
120115
try {
121116
final nsLookupResult = await InternetAddress.lookup('google.com');
122-
if (nsLookupResult.isNotEmpty &&
123-
nsLookupResult[0].rawAddress.isNotEmpty) {
117+
if (nsLookupResult.isNotEmpty && nsLookupResult[0].rawAddress.isNotEmpty) {
124118
_initSubscription();
125119
}
126120
// on exception -> no real connection, set current state to none
127121
} on SocketException catch (_) {
128-
_currentConnectivityResult = ConnectivityResult.none;
122+
_currentConnectivityResult = [ConnectivityResult.none];
129123
}
130124
} else {
131125
_initSubscription();
132126
}
133127
} else {
134-
_currentConnectivityResult = result;
128+
_currentConnectivityResult = List.from(results, growable: false);
135129
}
136130
}
137131

packages/graphql_flutter/pubspec.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ dependencies:
1515
meta: ^1.7.0
1616
path_provider: ^2.0.1
1717
path: ^1.8.0
18-
connectivity_plus: ^5.0.0
18+
connectivity_plus: ^6.0.1
1919
hive: ^2.0.0
2020
plugin_platform_interface: ^2.0.0
2121
flutter_hooks: '>=0.18.2 <0.21.0'

0 commit comments

Comments
 (0)