Skip to content

Commit 325c2eb

Browse files
Merge pull request #621 from appwrite/feat-dart-flutter-inputfile-change
2 parents 731f039 + e420e10 commit 325c2eb

File tree

4 files changed

+38
-7
lines changed

4 files changed

+38
-7
lines changed

templates/dart/lib/src/input_file.dart.twig

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,42 @@ class InputFile {
66
final String? filename;
77
final String? contentType;
88

9-
/// Provide a file, use `path` for IO platforms
10-
/// and provide `bytes` for web platform
9+
@Deprecated('Use `InputFile.fromPath` or `InputFile.fromBytes` instead.')
1110
InputFile({this.path, this.filename, this.contentType, this.bytes}) {
1211
if (path == null && bytes == null) {
1312
throw {{ spec.title | caseUcfirst }}Exception('One of `path` or `bytes` is required');
1413
}
1514
}
15+
16+
InputFile._({this.path, this.filename, this.contentType, this.bytes}) {
17+
if (path == null && bytes == null) {
18+
throw {{ spec.title | caseUcfirst }}Exception('One of `path` or `bytes` is required');
19+
}
20+
}
21+
22+
/// Provide a file using `path`
23+
factory InputFile.fromPath({
24+
required String path,
25+
String? filename,
26+
String? contentType,
27+
}) {
28+
return InputFile._(
29+
path: path,
30+
filename: filename,
31+
contentType: contentType,
32+
);
33+
}
34+
35+
/// Provide a file using `bytes`
36+
factory InputFile.fromBytes({
37+
required List<int> bytes,
38+
required String filename,
39+
String? contentType,
40+
}) {
41+
return InputFile._(
42+
bytes: bytes,
43+
filename: filename,
44+
contentType: contentType,
45+
);
46+
}
1647
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
name: {{ language.params.packageName }}_example
22
environment:
3-
sdk: '>=2.6.0 <3.0.0'
3+
sdk: '>=2.17.0 <3.0.0'

tests/languages/dart/tests.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,13 @@ void main() async {
5151
final res = await general.redirect();
5252
print(res['result']);
5353

54-
var file = InputFile(path: '../../resources/file.png',
54+
var file = InputFile.fromPath(path: '../../resources/file.png',
5555
filename: 'file.png');
5656
response = await general.upload(
5757
x: 'string', y: 123, z: ['string in array'], file: file);
5858
print(response.result);
5959

60-
file = InputFile(path: '../../resources/large_file.mp4', filename: 'large_file.mp4');
60+
file = InputFile.fromPath(path: '../../resources/large_file.mp4', filename: 'large_file.mp4');
6161
response = await general.upload(
6262
x: 'string', y: 123, z: ['string in array'], file: file);
6363
print(response.result);

tests/languages/flutter/tests.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,12 @@ void main() async {
7878
final res = await general.redirect();
7979
print(res['result']);
8080

81-
var file = InputFile(path: '../../resources/file.png', filename: 'file.png');
81+
var file = InputFile.fromPath(path: '../../resources/file.png', filename: 'file.png');
8282
response = await general.upload(
8383
x: 'string', y: 123, z: ['string in array'], file: file);
8484
print(response.result);
8585

86-
file = InputFile(path: '../../resources/large_file.mp4', filename: 'large_file.mp4');
86+
file = InputFile.fromPath(path: '../../resources/large_file.mp4', filename: 'large_file.mp4');
8787
response = await general.upload(
8888
x: 'string', y: 123, z: ['string in array'], file: file);
8989
print(response.result);

0 commit comments

Comments
 (0)