enable avoid dynamic calls lint (#560)
Co-authored-by: Nate Bosch <nbosch@google.com>
diff --git a/CHANGELOG.md b/CHANGELOG.md
index caa987e..2750afd 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,5 @@
+## 0.13.2-dev
+
## 0.13.1
* Fix code samples in `README` to pass a `Uri` instance.
diff --git a/analysis_options.yaml b/analysis_options.yaml
index 126c3b9..c2c719d 100644
--- a/analysis_options.yaml
+++ b/analysis_options.yaml
@@ -12,6 +12,7 @@
- avoid_bool_literals_in_conditional_expressions
- avoid_catching_errors
- avoid_classes_with_only_static_members
+ - avoid_dynamic_calls
- avoid_empty_else
- avoid_function_literals_in_foreach_calls
- avoid_init_to_null
diff --git a/example/main.dart b/example/main.dart
index d6b4997..3414918 100644
--- a/example/main.dart
+++ b/example/main.dart
@@ -1,4 +1,5 @@
import 'dart:convert' as convert;
+
import 'package:http/http.dart' as http;
void main(List<String> arguments) async {
@@ -10,7 +11,8 @@
// Await the http get response, then decode the json-formatted response.
var response = await http.get(url);
if (response.statusCode == 200) {
- var jsonResponse = convert.jsonDecode(response.body);
+ var jsonResponse =
+ convert.jsonDecode(response.body) as Map<String, dynamic>;
var itemCount = jsonResponse['totalItems'];
print('Number of books about http: $itemCount.');
} else {
diff --git a/pubspec.yaml b/pubspec.yaml
index 9ba4d71..635b795 100644
--- a/pubspec.yaml
+++ b/pubspec.yaml
@@ -1,5 +1,5 @@
name: http
-version: 0.13.1
+version: 0.13.2-dev
homepage: https://github.com/dart-lang/http
description: A composable, multi-platform, Future-based API for HTTP requests.
diff --git a/test/io/client_test.dart b/test/io/client_test.dart
index e5bd66f..d856efb 100644
--- a/test/io/client_test.dart
+++ b/test/io/client_test.dart
@@ -3,7 +3,6 @@
// BSD-style license that can be found in the LICENSE file.
@TestOn('vm')
-
import 'dart:convert';
import 'dart:io';
@@ -117,7 +116,8 @@
var bytesString = await response.stream.bytesToString();
client.close();
- var headers = jsonDecode(bytesString)['headers'] as Map<String, dynamic>;
+ var headers = (jsonDecode(bytesString) as Map<String, dynamic>)['headers']
+ as Map<String, dynamic>;
var contentType = (headers['content-type'] as List).single;
expect(contentType, startsWith('multipart/form-data; boundary='));
});
diff --git a/test/io/utils.dart b/test/io/utils.dart
index eb1234c..ac4414f 100644
--- a/test/io/utils.dart
+++ b/test/io/utils.dart
@@ -83,20 +83,23 @@
requestBody = requestBodyBytes;
}
- var content = <String, dynamic>{
- 'method': request.method,
- 'path': request.uri.path,
- 'headers': {}
- };
- if (requestBody != null) content['body'] = requestBody;
+ final headers = <String, List<String>>{};
+
request.headers.forEach((name, values) {
// These headers are automatically generated by dart:io, so we don't
// want to test them here.
if (name == 'cookie' || name == 'host') return;
- content['headers'][name] = values;
+ headers[name] = values;
});
+ var content = <String, dynamic>{
+ 'method': request.method,
+ 'path': request.uri.path,
+ if (requestBody != null) 'body': requestBody,
+ 'headers': headers,
+ };
+
var body = json.encode(content);
response
..contentLength = body.length