Closed
Description
A flutter web app that uses dart:html runs fine in release mode but fails when running with debug.
We are writing a Flutter app that runs on the browser and accepts files dropped to the browser window.
The app listens for onDrop
events and tries to retrieve the dropped object. In our code we are using typed variables (not dynamic
)
import 'dart:html' as html;
void _onDrop(html.MouseEvent mouseEvent) async {
mouseEvent.stopImmediatePropagation();
mouseEvent.preventDefault();
html.DataTransfer transfer = mouseEvent.dataTransfer;
if (transfer.items == null || transfer.items!.length == null) return;
List<html.Entry> entries = [];
for (int i = 0; i < transfer.items!.length!; i++) {
entries.add(transfer.items![i].getAsEntry());
}
}
html.document.body!.onDrop.listen(_onDrop);
This code runs fine when running in release mode:
flutter run --release -d chrome
However it fails when running in debug mode:
flutter run --debug -d chrome
Attempting to install properties from non-Object type 'FileEntry' onto the native JS Object.
Error: Expected a value of type 'Entry', but got one of type 'JavaScriptObject'
at Object.throw_ [as throw] (http://localhost:54262/dart_sdk.js:5061:11)
at Object.castError (http://localhost:54262/dart_sdk.js:5020:15)
at Object.cast [as as] (http://localhost:54262/dart_sdk.js:5345:17)
at Function.as_C [as as] (http://localhost:54262/dart_sdk.js:4966:19)
at Array.[dartx.add] (http://localhost:54262/dart_sdk.js:16274:11)
at io_html.DropTarget.new._onDrop (http://localhost:54262/packages/spaces_client/pages/theming.dart.lib.js:35303:33)
at _onDrop.next (<anonymous>)
at runBody (http://localhost:54262/dart_sdk.js:38659:34)
at Object._async [as async] (http://localhost:54262/dart_sdk.js:38690:7)
at io_html.DropTarget.new.[_onDrop] (http://localhost:54262/packages/spaces_client/pages/theming.dart.lib.js:35295:20)
at Object._checkAndCall (http://localhost:54262/dart_sdk.js:5268:16)
at Object.dcall (http://localhost:54262/dart_sdk.js:5273:17)
at HTMLBodyElement.<anonymous> (http://localhost:54262/dart_sdk.js:101824:100)
It seems that using the type Entry
(dart API) confuses the debugger because there is no native JavaScript object that matches this name and/or signature.
- Dart/Flutter SDK version: Flutter (Channel stable, 2.5.3, on macOS 12.0.1 21A559 darwin-x64, locale de-DE)