Skip to content

Commit f68bd68

Browse files
committed
Bump min Dart SDK version to 2.3.0
1 parent 3d6e3dd commit f68bd68

File tree

3 files changed

+39
-39
lines changed

3 files changed

+39
-39
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

77
## [Unreleased]
8+
### Changed
9+
- Dart >= 2.3.0 is now required
10+
811
### Added
912
- `JsonApiClient` has `const` constructor
1013

lib/src/client.dart

Lines changed: 35 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -29,61 +29,63 @@ class JsonApiClient {
2929
/// Fetches a resource collection by sending a GET request to the [uri].
3030
/// Use [headers] to pass extra HTTP headers.
3131
Future<Response<ResourceCollectionData>> fetchCollection(Uri uri,
32-
{Map<String, String> headers}) =>
32+
{Map<String, String> headers = const {}}) =>
3333
_get(_parser.parseResourceCollectionData, uri, headers);
3434

3535
/// Fetches a single resource
3636
/// Use [headers] to pass extra HTTP headers.
3737
Future<Response<ResourceData>> fetchResource(Uri uri,
38-
{Map<String, String> headers}) =>
38+
{Map<String, String> headers = const {}}) =>
3939
_get(_parser.parseResourceData, uri, headers);
4040

4141
/// Fetches a to-one relationship
4242
/// Use [headers] to pass extra HTTP headers.
43-
Future<Response<ToOne>> fetchToOne(Uri uri, {Map<String, String> headers}) =>
43+
Future<Response<ToOne>> fetchToOne(Uri uri,
44+
{Map<String, String> headers = const {}}) =>
4445
_get(_parser.parseToOne, uri, headers);
4546

4647
/// Fetches a to-many relationship
4748
/// Use [headers] to pass extra HTTP headers.
4849
Future<Response<ToMany>> fetchToMany(Uri uri,
49-
{Map<String, String> headers}) =>
50+
{Map<String, String> headers = const {}}) =>
5051
_get(_parser.parseToMany, uri, headers);
5152

5253
/// Fetches a to-one or to-many relationship.
5354
/// The actual type of the relationship can be determined afterwards.
5455
/// Use [headers] to pass extra HTTP headers.
5556
Future<Response<Relationship>> fetchRelationship(Uri uri,
56-
{Map<String, String> headers}) =>
57+
{Map<String, String> headers = const {}}) =>
5758
_get(_parser.parseRelationship, uri, headers);
5859

5960
/// Creates a new resource. The resource will be added to a collection
6061
/// according to its type.
6162
///
6263
/// https://jsonapi.org/format/#crud-creating
6364
Future<Response<ResourceData>> createResource(Uri uri, Resource resource,
64-
{Map<String, String> headers}) =>
65+
{Map<String, String> headers = const {}}) =>
6566
_post(_parser.parseResourceData, uri,
6667
ResourceData(ResourceObject.fromResource(resource)), headers);
6768

6869
/// Deletes the resource.
6970
///
7071
/// https://jsonapi.org/format/#crud-deleting
71-
Future<Response> deleteResource(Uri uri, {Map<String, String> headers}) =>
72+
Future<Response> deleteResource(Uri uri,
73+
{Map<String, String> headers = const {}}) =>
7274
_delete(null, uri, headers);
7375

7476
/// Updates the resource via PATCH request.
7577
///
7678
/// https://jsonapi.org/format/#crud-updating
7779
Future<Response<ResourceData>> updateResource(Uri uri, Resource resource,
78-
{Map<String, String> headers}) =>
80+
{Map<String, String> headers = const {}}) =>
7981
_patch(_parser.parseResourceData, uri,
8082
ResourceData(ResourceObject.fromResource(resource)), headers);
8183

8284
/// Updates a to-one relationship via PATCH request
8385
///
8486
/// https://jsonapi.org/format/#crud-updating-to-one-relationships
8587
Future<Response<ToOne>> replaceToOne(Uri uri, Identifier identifier,
86-
{Map<String, String> headers}) =>
88+
{Map<String, String> headers = const {}}) =>
8789
_patch(
8890
_parser.parseToOne,
8991
uri,
@@ -92,7 +94,8 @@ class JsonApiClient {
9294

9395
/// Removes a to-one relationship. This is equivalent to calling [replaceToOne]
9496
/// with id = null.
95-
Future<Response<ToOne>> deleteToOne(Uri uri, {Map<String, String> headers}) =>
97+
Future<Response<ToOne>> deleteToOne(Uri uri,
98+
{Map<String, String> headers = const {}}) =>
9699
replaceToOne(uri, null, headers: headers);
97100

98101
/// Replaces a to-many relationship with the given set of [identifiers].
@@ -103,7 +106,7 @@ class JsonApiClient {
103106
///
104107
/// https://jsonapi.org/format/#crud-updating-to-many-relationships
105108
Future<Response<ToMany>> replaceToMany(Uri uri, List<Identifier> identifiers,
106-
{Map<String, String> headers}) =>
109+
{Map<String, String> headers = const {}}) =>
107110
_patch(_parser.parseToMany, uri,
108111
ToMany(identifiers.map(IdentifierObject.fromIdentifier)), headers);
109112

@@ -126,55 +129,49 @@ class JsonApiClient {
126129
///
127130
/// https://jsonapi.org/format/#crud-updating-to-many-relationships
128131
Future<Response<ToMany>> addToMany(Uri uri, List<Identifier> identifiers,
129-
{Map<String, String> headers}) =>
132+
{Map<String, String> headers = const {}}) =>
130133
_post(_parser.parseToMany, uri,
131134
ToMany(identifiers.map(IdentifierObject.fromIdentifier)), headers);
132135

133136
Future<Response<D>> _get<D extends PrimaryData>(
134137
D parse(Object _), uri, Map<String, String> headers) =>
135138
_call(
136139
parse,
137-
(_) => _.get(uri,
138-
headers: {}
139-
..addAll(headers ?? {})
140-
..addAll({'Accept': contentType})));
140+
(_) => _.get(uri, headers: {
141+
...headers,
142+
'Accept': contentType,
143+
}));
141144

142145
Future<Response<D>> _post<D extends PrimaryData>(D parse(Object _), uri,
143146
PrimaryData data, Map<String, String> headers) =>
144147
_call(
145148
parse,
146-
(_) => _.post(uri,
147-
body: json.encode(Document(data)),
148-
headers: {}
149-
..addAll(headers ?? {})
150-
..addAll({
151-
'Accept': contentType,
152-
'Content-Type': contentType,
153-
})));
149+
(_) => _.post(uri, body: _body(data), headers: {
150+
...headers,
151+
'Accept': contentType,
152+
'Content-Type': contentType,
153+
}));
154154

155155
Future<Response<D>> _delete<D extends PrimaryData>(
156156
D parse(Object _), uri, Map<String, String> headers) =>
157157
_call(
158158
parse,
159-
(_) => _.delete(uri,
160-
headers: {}
161-
..addAll(headers ?? {})
162-
..addAll({
163-
'Accept': contentType,
164-
})));
159+
(_) => _.delete(uri, headers: {
160+
'Accept': contentType,
161+
...headers,
162+
}));
165163

166164
Future<Response<D>> _patch<D extends PrimaryData>(D parse(Object _), uri,
167165
PrimaryData data, Map<String, String> headers) =>
168166
_call(
169167
parse,
170-
(_) => _.patch(uri,
171-
body: json.encode(Document(data)),
172-
headers: {}
173-
..addAll(headers ?? {})
174-
..addAll({
175-
'Accept': contentType,
176-
'Content-Type': contentType,
177-
})));
168+
(_) => _.patch(uri, body: _body(data), headers: {
169+
...headers,
170+
'Accept': contentType,
171+
'Content-Type': contentType,
172+
}));
173+
174+
String _body(PrimaryData data) => json.encode(Document(data));
178175

179176
Future<Response<D>> _call<D extends PrimaryData>(D parse(Object json),
180177
Future<http.Response> fn(http.Client client)) async {

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@ dev_dependencies:
1414
test: "^1.6.1"
1515
uuid: "^2.0.1"
1616
environment:
17-
sdk: ">=2.0.0 <3.0.0"
17+
sdk: ">=2.3.0 <3.0.0"

0 commit comments

Comments
 (0)