universal_html icon indicating copy to clipboard operation
universal_html copied to clipboard

Method 'close' cannot be called on 'WindowBase?' because it is potentially null.

Open Ruud14 opened this issue 1 year ago • 1 comments

The following code works correctly on web:

var other = html.window.open(...);
other.close();

I obviously have this code behind a kIsWeb, such that this code is never run on Android or iOS. However, when I try to build my project for android I get the following error:

` Error: Method 'close' cannot be called on 'WindowBase?' because it is potentially null.

  • 'WindowBase' is from 'package:universal_html/src/html.dart' ('../../../AppData/Local/Pub/Cache/hosted/pub.dev/universal_html-2.2.4/lib/src/html.dart'). Try calling using ?. instead. other.close(); ^^^^^

`

As the error states, this can be fixed by changing the code to other?.close();, however my VScode complains about this stating that "The receiver can't be null, so the null-aware operator '?.' is unnecessary."

Thus it seems like the return value of .open is not nullable on web, but nullable on other platforms.

Ruud14 avatar Nov 25 '23 14:11 Ruud14