Skip to content

Commit 786fbd1

Browse files
committed
update file type
1 parent 851df13 commit 786fbd1

File tree

2 files changed

+16
-24
lines changed

2 files changed

+16
-24
lines changed
Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,17 @@
1+
import 'package:flutter/foundation.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

79
/// 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+
InputFile({this.path, this.filename, this.contentType, this.bytes}) {
11+
if (kIsWeb && bytes == null) {
12+
throw {{ spec.title | caseUcfirs }}Exception('On web `bytes` is required');
13+
} else if(path == null) {
14+
throw {{ spec.title | caseUcfirs }}Exception('On IO platforms `path is required`);
15+
}
2016
}
2117
}
Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,17 @@
1+
import 'package:flutter/foundation.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

79
/// 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+
InputFile({this.path, this.filename, this.contentType, this.bytes}) {
11+
if (kIsWeb && bytes == null) {
12+
throw {{ spec.title | caseUcfirs }}Exception('On web `bytes` is required');
13+
} else if(path == null) {
14+
throw {{ spec.title | caseUcfirs }}Exception('On IO platforms `path is required`);
15+
}
2016
}
2117
}

0 commit comments

Comments
 (0)