Skip to content

Commit 14a6e52

Browse files
Merge pull request #1149 from appwrite/chore-improve-flutter-dart-sdk-scores
chore(flutter): improve dart and flutter pub.dev scores
2 parents 45c7be1 + 1380667 commit 14a6e52

21 files changed

+87
-65
lines changed

src/SDK/Language/Dart.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,11 @@ public function getFiles(): array
372372
'destination' => '/pubspec.yaml',
373373
'template' => 'dart/pubspec.yaml.twig',
374374
],
375+
[
376+
'scope' => 'default',
377+
'destination' => '/analysis_options.yaml',
378+
'template' => 'dart/analysis_options.yaml.twig',
379+
],
375380
[
376381
'scope' => 'default',
377382
'destination' => '/lib/client_io.dart',

src/SDK/Language/Flutter.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,11 @@ public function getFiles(): array
240240
'destination' => '/pubspec.yaml',
241241
'template' => 'flutter/pubspec.yaml.twig',
242242
],
243+
[
244+
'scope' => 'default',
245+
'destination' => '/analysis_options.yaml',
246+
'template' => 'flutter/analysis_options.yaml.twig',
247+
],
243248
[
244249
'scope' => 'service',
245250
'destination' => '/lib/services/{{service.name | caseDash}}.dart',
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
include: package:lints/recommended.yaml

templates/dart/lib/src/enums.dart.twig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@ enum ResponseType {
1616
/// Transform the response data to a String encoded with UTF8.
1717
plain,
1818

19-
/// Get original bytes, the type of response will be List<int>
19+
/// Get original bytes, the type of response will be `List<int>`
2020
bytes
2121
}

templates/dart/lib/src/enums/enum.dart.twig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ part of '../../enums.dart';
33
enum {{ enum.name | caseUcfirst | overrideIdentifier }} {
44
{%~ for value in enum.enum %}
55
{%~ set key = enum.keys is empty ? value : enum.keys[loop.index0] %}
6-
{{ key | caseEnumKey }}(value: '{{ value }}'){% if not loop.last %},{% else %};{% endif %}
6+
{{ key | caseEnumKey | escapeKeyword }}(value: '{{ value }}'){% if not loop.last %},{% else %};{% endif %}
77

88
{%~ endfor %}
99

templates/dart/pubspec.yaml.twig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@ dependencies:
1111
http: '>=0.13.6 <2.0.0'
1212
1313
dev_dependencies:
14-
lints: ^4.0.0
14+
lints: ^6.0.0
1515
test: ^1.25.8
1616
mockito: ^5.4.4

templates/dart/test/query_test.dart.twig

Lines changed: 37 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
1+
import 'dart:convert';
2+
13
import 'package:{{ language.params.packageName }}/{{ language.params.packageName }}.dart';
24
{% if 'dart' in language.params.packageName %}
35
import 'package:test/test.dart';
46
{% else %}
57
import 'package:flutter_test/flutter_test.dart';
68
{% endif %}
79

8-
class BasicFilterQueryTest {
10+
class BasicFilterQueryTest<T> {
911
final String description;
10-
final dynamic value;
11-
final String expectedValues;
12+
final T value;
13+
final List<T> expectedValues;
1214

1315
BasicFilterQueryTest({
1416
required this.description,
@@ -23,7 +25,7 @@ void main() {
2325
BasicFilterQueryTest(
2426
description: 'with a string',
2527
value: 's',
26-
expectedValues: ["s"],
28+
expectedValues: ['s'],
2729
),
2830
BasicFilterQueryTest(
2931
description: 'with an integer',
@@ -48,14 +50,14 @@ void main() {
4850
BasicFilterQueryTest(
4951
description: 'with a list',
5052
value: ['a', 'b', 'c'],
51-
expectedValues: ["a","b","c"],
53+
expectedValues: ['a', 'b', 'c'],
5254
),
5355
];
5456

5557
group('equal()', () {
5658
for (var t in tests) {
5759
test(t.description, () {
58-
final query = Query.equal('attr', t.value).toJson();
60+
final query = jsonDecode(Query.equal('attr', t.value));
5961
expect(query['attribute'], 'attr');
6062
expect(query['values'], t.expectedValues);
6163
expect(query['method'], 'equal');
@@ -66,7 +68,7 @@ void main() {
6668
group('notEqual()', () {
6769
for (var t in tests) {
6870
test(t.description, () {
69-
final query = Query.notEqual('attr', t.value).toJson();
71+
final query = jsonDecode(Query.notEqual('attr', t.value));
7072
expect(query['attribute'], 'attr');
7173
expect(query['values'], t.expectedValues);
7274
expect(query['method'], 'notEqual');
@@ -77,7 +79,7 @@ void main() {
7779
group('lessThan()', () {
7880
for (var t in tests) {
7981
test(t.description, () {
80-
final query = Query.lessThan('attr', t.value).toJson();
82+
final query = jsonDecode(Query.lessThan('attr', t.value));
8183
expect(query['attribute'], 'attr');
8284
expect(query['values'], t.expectedValues);
8385
expect(query['method'], 'lessThan');
@@ -88,7 +90,7 @@ void main() {
8890
group('lessThanEqual()', () {
8991
for (var t in tests) {
9092
test(t.description, () {
91-
final query = Query.lessThanEqual('attr', t.value).toJson();
93+
final query = jsonDecode(Query.lessThanEqual('attr', t.value));
9294
expect(query['attribute'], 'attr');
9395
expect(query['values'], t.expectedValues);
9496
expect(query['method'], 'lessThanEqual');
@@ -99,7 +101,7 @@ void main() {
99101
group('greaterThan()', () {
100102
for (var t in tests) {
101103
test(t.description, () {
102-
final query = Query.greaterThan('attr', t.value).toJson();
104+
final query = jsonDecode(Query.greaterThan('attr', t.value));
103105
expect(query['attribute'], 'attr');
104106
expect(query['values'], t.expectedValues);
105107
expect(query['method'], 'greaterThan');
@@ -110,7 +112,7 @@ void main() {
110112
group('greaterThanEqual()', () {
111113
for (var t in tests) {
112114
test(t.description, () {
113-
final query = Query.greaterThanEqual('attr', t.value).toJson();
115+
final query = jsonDecode(Query.greaterThanEqual('attr', t.value));
114116
expect(query['attribute'], 'attr');
115117
expect(query['values'], t.expectedValues);
116118
expect(query['method'], 'greaterThanEqual');
@@ -120,172 +122,172 @@ void main() {
120122
});
121123

122124
test('returns search', () {
123-
final query = Query.search('attr', 'keyword1 keyword2').toJson();
125+
final query = jsonDecode(Query.search('attr', 'keyword1 keyword2'));
124126
expect(query['attribute'], 'attr');
125127
expect(query['values'], ['keyword1 keyword2']);
126128
expect(query['method'], 'search');
127129
});
128130

129131
test('returns isNull', () {
130-
final query = Query.isNull('attr').toJson();
132+
final query = jsonDecode(Query.isNull('attr'));
131133
expect(query['attribute'], 'attr');
132134
expect(query['values'], null);
133135
expect(query['method'], 'isNull');
134136
});
135137

136138
test('returns isNotNull', () {
137-
final query = Query.isNotNull('attr', 'keyword1 keyword2').toJson();
139+
final query = jsonDecode(Query.isNotNull('attr'));
138140
expect(query['attribute'], 'attr');
139141
expect(query['values'], null);
140142
expect(query['method'], 'isNotNull');
141143
});
142144

143145
group('between()', () {
144146
test('with integers', () {
145-
final query = Query.between('attr', 1, 2).toJson();
147+
final query = jsonDecode(Query.between('attr', 1, 2));
146148
expect(query['attribute'], 'attr');
147149
expect(query['values'], [1, 2]);
148150
expect(query['method'], 'between');
149151
});
150152

151153
test('with doubles', () {
152-
final query = Query.between('attr', 1.0, 2.0).toJson();
154+
final query = jsonDecode(Query.between('attr', 1.0, 2.0));
153155
expect(query['attribute'], 'attr');
154156
expect(query['values'], [1.0, 2.0]);
155157
expect(query['method'], 'between');
156158
});
157159

158160
test('with strings', () {
159-
final query = Query.between('attr', 'a', 'z').toJson();
161+
final query = jsonDecode(Query.between('attr', 'a', 'z'));
160162
expect(query['attribute'], 'attr');
161163
expect(query['values'], ['a', 'z']);
162164
expect(query['method'], 'between');
163165
});
164166
});
165167

166168
test('returns select', () {
167-
final query = Query.select(['attr1', 'attr2']).toJson();
169+
final query = jsonDecode(Query.select(['attr1', 'attr2']));
168170
expect(query['attribute'], null);
169171
expect(query['values'], ['attr1', 'attr2']);
170172
expect(query['method'], 'select');
171173
});
172174

173175
test('returns orderAsc', () {
174-
final query = Query.orderAsc('attr').toJson();
176+
final query = jsonDecode(Query.orderAsc('attr'));
175177
expect(query['attribute'], 'attr');
176178
expect(query['values'], null);
177179
expect(query['method'], 'orderAsc');
178180
});
179181

180182
test('returns orderDesc', () {
181-
final query = Query.orderDesc('attr').toJson();
183+
final query = jsonDecode(Query.orderDesc('attr'));
182184
expect(query['attribute'], 'attr');
183185
expect(query['values'], null);
184186
expect(query['method'], 'orderDesc');
185187
});
186188

187189
test('returns cursorBefore', () {
188-
final query = Query.cursorBefore('custom').toJson();
190+
final query = jsonDecode(Query.cursorBefore('custom'));
189191
expect(query['attribute'], null);
190192
expect(query['values'], 'custom');
191193
expect(query['method'], 'cursorBefore');
192194
});
193195

194196
test('returns cursorAfter', () {
195-
final query = Query.cursorAfter('custom').toJson();
197+
final query = jsonDecode(Query.cursorAfter('custom'));
196198
expect(query['attribute'], null);
197199
expect(query['values'], 'custom');
198200
expect(query['method'], 'cursorAfter');
199201
});
200202

201203
test('returns limit', () {
202-
final query = Query.limit(1).toJson();
204+
final query = jsonDecode(Query.limit(1));
203205
expect(query['attribute'], null);
204206
expect(query['values'], 1);
205207
expect(query['method'], 'limit');
206208
});
207209

208210
test('returns offset', () {
209-
final query = Query.offset(1).toJson();
211+
final query = jsonDecode(Query.offset(1));
210212
expect(query['attribute'], null);
211213
expect(query['values'], 1);
212214
expect(query['method'], 'offset');
213215
});
214216

215217
test('returns notContains', () {
216-
final query = Query.notContains('attr', 'value').toJson();
218+
final query = jsonDecode(Query.notContains('attr', 'value'));
217219
expect(query['attribute'], 'attr');
218220
expect(query['values'], ['value']);
219221
expect(query['method'], 'notContains');
220222
});
221223

222224
test('returns notSearch', () {
223-
final query = Query.notSearch('attr', 'keyword1 keyword2').toJson();
225+
final query = jsonDecode(Query.notSearch('attr', 'keyword1 keyword2'));
224226
expect(query['attribute'], 'attr');
225227
expect(query['values'], ['keyword1 keyword2']);
226228
expect(query['method'], 'notSearch');
227229
});
228230

229231
group('notBetween()', () {
230232
test('with integers', () {
231-
final query = Query.notBetween('attr', 1, 2).toJson();
233+
final query = jsonDecode(Query.notBetween('attr', 1, 2));
232234
expect(query['attribute'], 'attr');
233235
expect(query['values'], [1, 2]);
234236
expect(query['method'], 'notBetween');
235237
});
236238

237239
test('with doubles', () {
238-
final query = Query.notBetween('attr', 1.0, 2.0).toJson();
240+
final query = jsonDecode(Query.notBetween('attr', 1.0, 2.0));
239241
expect(query['attribute'], 'attr');
240242
expect(query['values'], [1.0, 2.0]);
241243
expect(query['method'], 'notBetween');
242244
});
243245

244246
test('with strings', () {
245-
final query = Query.notBetween('attr', 'a', 'z').toJson();
247+
final query = jsonDecode(Query.notBetween('attr', 'a', 'z'));
246248
expect(query['attribute'], 'attr');
247249
expect(query['values'], ['a', 'z']);
248250
expect(query['method'], 'notBetween');
249251
});
250252
});
251253

252254
test('returns notStartsWith', () {
253-
final query = Query.notStartsWith('attr', 'prefix').toJson();
255+
final query = jsonDecode(Query.notStartsWith('attr', 'prefix'));
254256
expect(query['attribute'], 'attr');
255257
expect(query['values'], ['prefix']);
256258
expect(query['method'], 'notStartsWith');
257259
});
258260

259261
test('returns notEndsWith', () {
260-
final query = Query.notEndsWith('attr', 'suffix').toJson();
262+
final query = jsonDecode(Query.notEndsWith('attr', 'suffix'));
261263
expect(query['attribute'], 'attr');
262264
expect(query['values'], ['suffix']);
263265
expect(query['method'], 'notEndsWith');
264266
});
265267

266268
test('returns createdBefore', () {
267-
final query = Query.createdBefore('2023-01-01').toJson();
269+
final query = jsonDecode(Query.createdBefore('2023-01-01'));
268270
expect(query['attribute'], null);
269271
expect(query['values'], '2023-01-01');
270272
expect(query['method'], 'createdBefore');
271273
});
272274

273275
test('returns createdAfter', () {
274-
final query = Query.createdAfter('2023-01-01').toJson();
276+
final query = jsonDecode(Query.createdAfter('2023-01-01'));
275277
expect(query['attribute'], null);
276278
expect(query['values'], '2023-01-01');
277279
expect(query['method'], 'createdAfter');
278280
});
279281

280282
test('returns updatedBefore', () {
281-
final query = Query.updatedBefore('2023-01-01').toJson();
283+
final query = jsonDecode(Query.updatedBefore('2023-01-01'));
282284
expect(query['attribute'], null);
283285
expect(query['values'], '2023-01-01');
284286
expect(query['method'], 'updatedBefore');
285287
});
286288

287289
test('returns updatedAfter', () {
288-
final query = Query.updatedAfter('2023-01-01').toJson();
290+
final query = jsonDecode(Query.updatedAfter('2023-01-01'));
289291
expect(query['attribute'], null);
290292
expect(query['values'], '2023-01-01');
291293
expect(query['method'], 'updatedAfter');

templates/dart/test/src/enums_test.dart.twig

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@ import 'package:flutter_test/flutter_test.dart';
88
void main() {
99
group('name()', () {
1010
for (final method in HttpMethod.values) {
11-
test('returns ${method.toString().split('.').last.toUpperCase()} for $method', () {
11+
test(
12+
'returns ${method.toString().split('.').last.toUpperCase()} for $method',
13+
() {
1214
expect(method.name(), method.toString().split('.').last.toUpperCase());
1315
});
1416
}
1517
});
16-
}
18+
}

templates/dart/test/src/exception_test.dart.twig

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,13 @@ void main() {
1212
expect(exception1.toString(), equals('{{spec.title | caseUcfirst}}Exception'));
1313

1414
final exception2 = {{spec.title | caseUcfirst}}Exception('Some error message');
15-
expect(exception2.toString(), equals('{{spec.title | caseUcfirst}}Exception: , Some error message (0)'));
15+
expect(exception2.toString(),
16+
equals('AppwriteException: , Some error message (0)'));
1617

17-
final exception3 = {{spec.title | caseUcfirst}}Exception('Invalid request', 400, 'ValidationError');
18-
expect(exception3.toString(), equals('{{spec.title | caseUcfirst}}Exception: ValidationError, Invalid request (400)'));
18+
final exception3 =
19+
AppwriteException('Invalid request', 400, 'ValidationError');
20+
expect(exception3.toString(),
21+
equals('AppwriteException: ValidationError, Invalid request (400)'));
1922
});
2023
});
2124
}

templates/dart/test/src/input_file_test.dart.twig

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ void main() {
4040
});
4141

4242
test('creates InputFile from bytes', () {
43-
final inputFile = InputFile.fromBytes(bytes: [1, 2, 3], filename: 'file.txt');
43+
final inputFile =
44+
InputFile.fromBytes(bytes: [1, 2, 3], filename: 'file.txt');
4445

4546
expect(inputFile.path, isNull);
4647
expect(inputFile.filename, 'file.txt');

0 commit comments

Comments
 (0)