Skip to content

Commit a3df378

Browse files
committed
fix(analyze): Fix the analizer issues
1 parent 52bcd2c commit a3df378

File tree

7 files changed

+67
-47
lines changed

7 files changed

+67
-47
lines changed

example/lib/graphql_bloc/bloc.dart

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@ import 'package:graphql_flutter/graphql_flutter.dart';
44
import '../graphql_operation/mutations/mutations.dart' as mutations;
55
import '../graphql_operation/queries/readRepositories.dart' as queries;
66

7-
/// Create a ../local.dart file with YOUR_PERSONAL_ACCESS_TOKEN = '<YOUR_PERSONAL_ACCESS_TOKEN>'
8-
/// to make the example work
9-
import '../local.dart' show YOUR_PERSONAL_ACCESS_TOKEN;
7+
const String YOUR_PERSONAL_ACCESS_TOKEN = '<YOUR_PERSONAL_ACCESS_TOKEN>';
108

119
class Repo {
1210
const Repo({this.id, this.name, this.viewerHasStarred});

example/lib/graphql_widget/main.dart

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,9 @@ import 'package:graphql_flutter/graphql_flutter.dart';
44
import '../graphql_operation/mutations/mutations.dart' as mutations;
55
import '../graphql_operation/queries/readRepositories.dart' as queries;
66

7-
/// Create a ../local.dart file with YOUR_PERSONAL_ACCESS_TOKEN = '<YOUR_PERSONAL_ACCESS_TOKEN>'
8-
/// to make the example work
9-
import '../local.dart' show YOUR_PERSONAL_ACCESS_TOKEN;
7+
const String YOUR_PERSONAL_ACCESS_TOKEN = '<YOUR_PERSONAL_ACCESS_TOKEN>';
108

11-
final bool ENABLE_WEBSOCKETS = false;
9+
const bool ENABLE_WEBSOCKETS = false;
1210

1311
class GraphQLWidgetScreen extends StatelessWidget {
1412
const GraphQLWidgetScreen() : super();
@@ -186,7 +184,7 @@ class StarrableRepository extends StatelessWidget {
186184
document: starred ? mutations.removeStar : mutations.addStar,
187185
),
188186
builder: (RunMutation toggleStar, QueryResult result) {
189-
print([result.loading, optimistic]);
187+
print(<bool>[result.loading, optimistic]);
190188
return ListTile(
191189
leading: starred
192190
? const Icon(

lib/src/cache/in_memory.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ class InMemoryCache implements Cache {
126126
}
127127
try {
128128
final File file = await _localStorageFile;
129-
final storedHashMap = HashMap<String, dynamic>();
129+
final HashMap<String, dynamic> storedHashMap = HashMap<String, dynamic>();
130130

131131
if (file.existsSync()) {
132132
final Stream<List<int>> inputStream = file.openRead();

lib/src/cache/lazy_cache_map.dart

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import 'dart:core';
2-
import 'dart:collection';
32

43
import 'package:meta/meta.dart';
54

@@ -13,7 +12,7 @@ class LazyCacheMap extends LazyDereferencingMap {
1312
Map<String, Object> data, {
1413
@required Dereference dereference,
1514
CacheState cacheState,
16-
}) : this.cacheState =
15+
}) : cacheState =
1716
cacheState ?? (data is LazyCacheMap ? data.cacheState : null),
1817
super(data, dereference: dereference);
1918

lib/src/cache/optimistic.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,9 +146,9 @@ class OptimisticCache extends NormalizedInMemoryCache {
146146
patch.id == removeId || _parentPatchId(patch.id) == removeId,
147147
);
148148

149-
print([
149+
print(<dynamic>[
150150
optimisticPatches.length,
151-
optimisticPatches.map((p) => p.id),
151+
optimisticPatches.map<String>((OptimisticPatch p) => p.id),
152152
removeId
153153
]);
154154
}

lib/src/core/raw_operation_data.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class RawOperationData {
1313
Map<String, dynamic> variables,
1414
String operationName,
1515
}) : _operationName = operationName,
16-
this.variables = SplayTreeMap<String, dynamic>.of(
16+
variables = SplayTreeMap<String, dynamic>.of(
1717
variables ?? const <String, dynamic>{},
1818
);
1919

lib/src/socket_client.dart

Lines changed: 58 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,9 @@ class SocketClient {
8686
///
8787
/// If this instance is disposed, this method does nothing.
8888
Future<void> _connect() async {
89-
if (_connectionStateController.isClosed) return;
89+
if (_connectionStateController.isClosed) {
90+
return;
91+
}
9092

9193
_connectionStateController.value = SocketConnectionState.CONNECTING;
9294
print('Connecting to websocket: $url...');
@@ -105,15 +107,17 @@ class SocketClient {
105107
.map<GraphQLSocketMessage>(_parseSocketMessage);
106108

107109
if (config.inactivityTimeout != null) {
108-
_keepAliveSubscription = _connectionKeepAlive
109-
.timeout(config.inactivityTimeout, onTimeout: (event) {
110-
print(
111-
"Haven't received keep alive message for ${config.inactivityTimeout.inSeconds} seconds. Disconnecting..");
112-
event.close();
113-
_socket.close(WebSocketStatus.goingAway);
114-
_connectionStateController.value =
115-
SocketConnectionState.NOT_CONNECTED;
116-
}).listen(null);
110+
_keepAliveSubscription = _connectionKeepAlive.timeout(
111+
config.inactivityTimeout,
112+
onTimeout: (EventSink<ConnectionKeepAlive> event) {
113+
print(
114+
"Haven't received keep alive message for ${config.inactivityTimeout.inSeconds} seconds. Disconnecting..");
115+
event.close();
116+
_socket.close(WebSocketStatus.goingAway);
117+
_connectionStateController.value =
118+
SocketConnectionState.NOT_CONNECTED;
119+
},
120+
).listen(null);
117121
}
118122

119123
_messageSubscription = _messageStream.listen(
@@ -139,7 +143,9 @@ class SocketClient {
139143
_keepAliveSubscription?.cancel();
140144
_messageSubscription?.cancel();
141145

142-
if (_connectionStateController.isClosed) return;
146+
if (_connectionStateController.isClosed) {
147+
return;
148+
}
143149

144150
if (_connectionStateController.value != SocketConnectionState.NOT_CONNECTED)
145151
_connectionStateController.value = SocketConnectionState.NOT_CONNECTED;
@@ -149,9 +155,12 @@ class SocketClient {
149155
print(
150156
'Scheduling to connect in ${config.delayBetweenReconnectionAttempts.inSeconds} seconds...');
151157

152-
_reconnectTimer = Timer(config.delayBetweenReconnectionAttempts, () {
153-
_connect();
154-
});
158+
_reconnectTimer = Timer(
159+
config.delayBetweenReconnectionAttempts,
160+
() {
161+
_connect();
162+
},
163+
);
155164
} else {
156165
Timer.run(() => _connect());
157166
}
@@ -238,35 +247,51 @@ class SocketClient {
238247
.take(1);
239248

240249
final Observable<SocketConnectionState> waitForConnectedState = addTimeout
241-
? waitForConnectedStateWithoutTimeout
242-
.timeout(config.queryAndMutationTimeout, onTimeout: (e) {
243-
print('Connection timed out.');
244-
response.addError(TimeoutException('Connection timed out.'));
245-
e.close();
246-
response.close();
247-
})
250+
? waitForConnectedStateWithoutTimeout.timeout(
251+
config.queryAndMutationTimeout,
252+
onTimeout: (EventSink<SocketConnectionState> event) {
253+
print('Connection timed out.');
254+
response.addError(TimeoutException('Connection timed out.'));
255+
event.close();
256+
response.close();
257+
},
258+
)
248259
: waitForConnectedStateWithoutTimeout;
249260

250261
sub = waitForConnectedState.listen((_) {
251262
final Stream<GraphQLSocketMessage> dataErrorComplete =
252-
_messageStream.where((GraphQLSocketMessage message) {
253-
if (message is SubscriptionData) return message.id == id;
254-
if (message is SubscriptionError) return message.id == id;
255-
if (message is SubscriptionComplete) return message.id == id;
256-
return false;
257-
}).takeWhile((_) => !response.isClosed);
263+
_messageStream.where(
264+
(GraphQLSocketMessage message) {
265+
if (message is SubscriptionData) {
266+
return message.id == id;
267+
}
268+
269+
if (message is SubscriptionError) {
270+
return message.id == id;
271+
}
272+
273+
if (message is SubscriptionComplete) {
274+
return message.id == id;
275+
}
276+
277+
return false;
278+
},
279+
).takeWhile((_) => !response.isClosed);
258280

259281
final Stream<GraphQLSocketMessage> subscriptionComplete = addTimeout
260282
? dataErrorComplete
261283
.where((GraphQLSocketMessage message) =>
262284
message is SubscriptionComplete)
263285
.take(1)
264-
.timeout(config.queryAndMutationTimeout, onTimeout: (e) {
265-
print('Request timed out.');
266-
response.addError(TimeoutException('Request timed out.'));
267-
e.close();
268-
response.close();
269-
})
286+
.timeout(
287+
config.queryAndMutationTimeout,
288+
onTimeout: (EventSink<GraphQLSocketMessage> event) {
289+
print('Request timed out.');
290+
response.addError(TimeoutException('Request timed out.'));
291+
event.close();
292+
response.close();
293+
},
294+
)
270295
: dataErrorComplete
271296
.where((GraphQLSocketMessage message) =>
272297
message is SubscriptionComplete)

0 commit comments

Comments
 (0)