Skip to content

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

Open
@Ruud14

Description

@Ruud14

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions