Skip to content

Commit fdce08a

Browse files
authored
Improve some style (flutter#140)
- Rename a private variable with a typo. - Remove a class that was unnecessarily extending a concrete class without overrides. - Remove some trailing commas that expanded calls onto many more lines than necessary. - Remove explicit generic arguments that can be inferred. - Add blank lines following the first sentence of some doc comments. - Fix trailing whitespace and formatting in changelog.
1 parent dc20d2f commit fdce08a

3 files changed

Lines changed: 18 additions & 38 deletions

File tree

CHANGELOG.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
## 0.7.6-dev
22

3-
* Supports multiple header values in `Request` and `Response`:
4-
* `headersAll` field contains all the header values
5-
* `headers` field contains the same values as previously (appending values with `,`)
6-
* `headers` parameter in the constructor and in the `.change()` method accepts
7-
both `String` and `List<String>` values.
3+
* Supports multiple header values in `Request` and `Response`:
4+
* `headersAll` field contains all the header values
5+
* `headers` field contains the same values as previously (appending values
6+
with `,`)
7+
* `headers` parameter in the constructor and in the `.change()` method
8+
accepts both `String` and `List<String>` values.
89

910
## 0.7.5
1011

lib/src/headers.dart

Lines changed: 10 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ final _emptyHeaders = Headers._empty();
1111

1212
/// Unmodifiable, key-insensitive header map.
1313
class Headers extends UnmodifiableMapView<String, List<String>> {
14-
Map<String, String> _singeValues;
14+
Map<String, String> _singleValues;
1515

1616
factory Headers.from(Map<String, List<String>> values) {
1717
if (values == null || values.isEmpty) {
@@ -24,34 +24,15 @@ class Headers extends UnmodifiableMapView<String, List<String>> {
2424
}
2525

2626
Headers._(Map<String, List<String>> values)
27-
: super(
28-
CaseInsensitiveMap<List<String>>.from(
29-
Map<String, List<String>>.fromEntries(
30-
values.entries
31-
.where((e) => e.value != null && e.value.isNotEmpty)
32-
.map(
33-
(e) => MapEntry<String, List<String>>(
34-
e.key,
35-
List.unmodifiable(e.value),
36-
),
37-
),
38-
),
39-
),
40-
);
41-
42-
Headers._empty() : super(<String, List<String>>{});
43-
factory Headers.empty() => _emptyHeaders;
27+
: super(CaseInsensitiveMap.from(Map.fromEntries(values.entries
28+
.where((e) => e.value?.isNotEmpty ?? false)
29+
.map((e) => MapEntry(e.key, List.unmodifiable(e.value))))));
4430

45-
Map<String, String> get singleValues {
46-
return _singeValues ??= _SingleValueHeaders(
47-
CaseInsensitiveMap<String>.from(
48-
map((key, value) =>
49-
MapEntry<String, String>(key, joinHeaderValues(value))),
50-
),
51-
);
52-
}
53-
}
31+
Headers._empty() : super(const {});
32+
factory Headers.empty() => _emptyHeaders;
5433

55-
class _SingleValueHeaders extends UnmodifiableMapView<String, String> {
56-
_SingleValueHeaders(Map<String, String> map) : super(map);
34+
Map<String, String> get singleValues => _singleValues ??= UnmodifiableMapView(
35+
CaseInsensitiveMap.from(
36+
map((key, value) => MapEntry(key, joinHeaderValues(value)))),
37+
);
5738
}

lib/src/message.dart

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,15 @@ final _defaultHeaders = Headers.from({
2525
abstract class Message {
2626
final Headers _headers;
2727

28-
/// The HTTP headers.
29-
/// The keys in this Map are normalized, and access is case-insensitive.
28+
/// The HTTP headers with case-insensitive keys.
3029
///
3130
/// If a header occurs more than once in the query string, they are mapped to
3231
/// by concatenating them with a comma.
3332
///
3433
/// The returned map is unmodifiable.
3534
Map<String, String> get headers => _headers.singleValues;
3635

37-
/// The HTTP headers with multiple values.
38-
/// The keys in this Map are normalized, and access is case-insensitive.
36+
/// The HTTP headers with multiple values with case-insensitive keys.
3937
///
4038
/// If a header occurs only once, its value is a singleton list.
4139
/// If a header occurs with no value, the empty string is used as the value

0 commit comments

Comments
 (0)