@@ -12,8 +12,7 @@ typedef OnSubscriptionResult<TParsed> = void Function(
12
12
GraphQLClient ? client,
13
13
);
14
14
15
- typedef SubscriptionBuilder <TParsed > = Widget Function (
16
- QueryResult <TParsed > result);
15
+ typedef SubscriptionBuilder <TParsed > = Widget Function (QueryResult <TParsed > result);
17
16
18
17
QueryResult <TParsed > useSubscription <TParsed >(
19
18
SubscriptionOptions <TParsed > options, {
@@ -59,18 +58,16 @@ class _SubscriptionHook<TParsed> extends Hook<Stream<QueryResult<TParsed>>> {
59
58
required this .onSubscriptionResult,
60
59
});
61
60
@override
62
- HookState <Stream <QueryResult <TParsed >>, Hook <Stream <QueryResult <TParsed >>>>
63
- createState () {
61
+ HookState <Stream <QueryResult <TParsed >>, Hook <Stream <QueryResult <TParsed >>>> createState () {
64
62
return _SubscriptionHookState ();
65
63
}
66
64
}
67
65
68
- class _SubscriptionHookState <TParsed > extends HookState <
69
- Stream <QueryResult <TParsed >>, _SubscriptionHook <TParsed >> {
66
+ class _SubscriptionHookState <TParsed > extends HookState <Stream <QueryResult <TParsed >>, _SubscriptionHook <TParsed >> {
70
67
late Stream <QueryResult <TParsed >> stream;
71
68
72
- ConnectivityResult ? _currentConnectivityResult;
73
- StreamSubscription <ConnectivityResult >? _networkSubscription;
69
+ List < ConnectivityResult > _currentConnectivityResult = [ ConnectivityResult .none] ;
70
+ StreamSubscription <List < ConnectivityResult > >? _networkSubscription;
74
71
75
72
void _initSubscription () {
76
73
final client = hook.client;
@@ -88,8 +85,7 @@ class _SubscriptionHookState<TParsed> extends HookState<
88
85
void initHook () {
89
86
super .initHook ();
90
87
_initSubscription ();
91
- _networkSubscription =
92
- Connectivity ().onConnectivityChanged.listen (_onNetworkChange);
88
+ _networkSubscription = Connectivity ().onConnectivityChanged.listen (_onNetworkChange);
93
89
}
94
90
95
91
@override
@@ -107,31 +103,29 @@ class _SubscriptionHookState<TParsed> extends HookState<
107
103
super .dispose ();
108
104
}
109
105
110
- Future <void > _onNetworkChange (ConnectivityResult result ) async {
106
+ Future <void > _onNetworkChange (List < ConnectivityResult > results ) async {
111
107
//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 );
116
111
117
112
// android connectivitystate cannot be trusted
118
113
// validate with nslookup
119
114
if (Platform .isAndroid) {
120
115
try {
121
116
final nsLookupResult = await InternetAddress .lookup ('google.com' );
122
- if (nsLookupResult.isNotEmpty &&
123
- nsLookupResult[0 ].rawAddress.isNotEmpty) {
117
+ if (nsLookupResult.isNotEmpty && nsLookupResult[0 ].rawAddress.isNotEmpty) {
124
118
_initSubscription ();
125
119
}
126
120
// on exception -> no real connection, set current state to none
127
121
} on SocketException catch (_) {
128
- _currentConnectivityResult = ConnectivityResult .none;
122
+ _currentConnectivityResult = [ ConnectivityResult .none] ;
129
123
}
130
124
} else {
131
125
_initSubscription ();
132
126
}
133
127
} else {
134
- _currentConnectivityResult = result ;
128
+ _currentConnectivityResult = List . from (results, growable : false ) ;
135
129
}
136
130
}
137
131
0 commit comments