Skip to content

Commit

Permalink
Merge pull request #1496 from vito-go/master
Browse files Browse the repository at this point in the history
Fix: TypeError: Instance of 'NativeByteBuffer': type 'NativeByteBuffer' is not a subtype of type 'List'.
  • Loading branch information
navaronbracke authored Apr 27, 2024
2 parents 137840a + 2357b8d commit 7b3eebf
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 8.0.3
### Web
Fixes a TypeError with `pickFiles()` when using the HTML renderer.

## 8.0.2
### iOS
Fixes the bug [#1412](https://github.com/miguelpruivo/flutter_file_picker/issues/1412) that picking a folder in iOS causes the original folder to be deleted.
Expand Down
20 changes: 18 additions & 2 deletions lib/_internal/file_picker_web.dart
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,24 @@ class FilePickerWeb extends FilePicker {
final blob = file.slice(start, end);
reader.readAsArrayBuffer(blob);
await EventStreamProviders.loadEvent.forTarget(reader).first;
yield reader.result as List<int>;
start += _readStreamChunkSize;
final JSAny? readerResult = reader.result;
if (readerResult == null) {
continue;
}
// TODO: use `isA<JSArrayBuffer>()` when switching to Dart 3.4
// Handle the ArrayBuffer type. This maps to a `ByteBuffer` in Dart.
if (readerResult.instanceOfString('ArrayBuffer')) {
yield (readerResult as JSArrayBuffer).toDart.asUint8List();
start += _readStreamChunkSize;
continue;
}
// TODO: use `isA<JSArray>()` when switching to Dart 3.4
// Handle the Array type.
if (readerResult.instanceOfString('Array')) {
// Assume this is a List<int>.
yield (readerResult as JSArray).toDart.cast<int>();
start += _readStreamChunkSize;
}
}
}
}
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ description: A package that allows you to use a native file explorer to pick sin
homepage: https://github.com/miguelpruivo/plugins_flutter_file_picker
repository: https://github.com/miguelpruivo/flutter_file_picker
issue_tracker: https://github.com/miguelpruivo/flutter_file_picker/issues
version: 8.0.2
version: 8.0.3

dependencies:
flutter:
Expand Down

0 comments on commit 7b3eebf

Please sign in to comment.