Skip to content

Commit 2b0dcee

Browse files
Merge pull request #467 from appwrite/fix-flutter-dart-file-type
2 parents 851df13 + 721a532 commit 2b0dcee

File tree

2 files changed

+19
-26
lines changed

2 files changed

+19
-26
lines changed
Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,16 @@
1+
import 'exception.dart';
2+
13
class InputFile {
24
late final String? path;
35
late final List<int>? bytes;
46
final String? filename;
57
final String? contentType;
68

7-
/// Provide a file using path
8-
InputFile({required this.path, this.filename, this.contentType}) {
9-
bytes = null;
10-
}
11-
12-
InputFile._internal(this.bytes, {this.filename, this.contentType}) {
13-
path = null;
14-
}
15-
16-
/// Provide a file using bytes
17-
factory InputFile.fromBytes(
18-
{required List<int> bytes, String? filename, String? contentType}) {
19-
return InputFile._internal(bytes, filename: filename, contentType: contentType);
9+
/// Provide a file, use `path` for IO platforms
10+
/// and provide `bytes` for web platform
11+
InputFile({this.path, this.filename, this.contentType, this.bytes}) {
12+
if (path == null && bytes == null) {
13+
throw {{ spec.title | caseUcfirst }}Exception('One of `path` or `bytes` is required');
14+
}
2015
}
2116
}
Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,19 @@
1+
import 'package:flutter/foundation.dart';
2+
import 'exception.dart';
3+
14
class InputFile {
25
late final String? path;
36
late final List<int>? bytes;
47
final String? filename;
58
final String? contentType;
69

7-
/// Provide a file using path
8-
InputFile({required this.path, this.filename, this.contentType}) {
9-
bytes = null;
10-
}
11-
12-
InputFile._internal(this.bytes, {this.filename, this.contentType}) {
13-
path = null;
14-
}
15-
16-
/// Provide a file using bytes
17-
factory InputFile.fromBytes(
18-
{required List<int> bytes, String? filename, String? contentType}) {
19-
return InputFile._internal(bytes, filename: filename, contentType: contentType);
10+
/// Provide a file, use `path` for IO platforms
11+
/// and provide `bytes` for web platform
12+
InputFile({this.path, this.filename, this.contentType, this.bytes}) {
13+
if (kIsWeb && bytes == null) {
14+
throw {{ spec.title | caseUcfirst }}Exception('On web `bytes` is required');
15+
} else if(!kIsWeb && path == null && bytes == null) {
16+
throw {{ spec.title | caseUcfirst }}Exception('On IO platforms one of `path` or `bytes` is required');
17+
}
2018
}
2119
}

0 commit comments

Comments
 (0)