easy_web_view icon indicating copy to clipboard operation
easy_web_view copied to clipboard

Compile-time Error: Method 'addPostFrameCallback' cannot be called on 'WidgetsBinding?' because it is potentially null.

Open magnuswikhog opened this issue 2 years ago • 4 comments

I just added this plugin to a Flutter Web project, but when I compile it I get

../../dev/flutter/.pub-cache/hosted/pub.dartlang.org/webview_windows-0.1.9/lib/src/webview.dart:481:29: Error: Method 'addPostFrameCallback' cannot be called on 'WidgetsBinding?' because it is potentially null.
 - 'WidgetsBinding' is from 'package:flutter/src/widgets/binding.dart' ('../../dev/flutter/packages/flutter/lib/src/widgets/binding.dart').
Try calling using ?. instead.
    WidgetsBinding.instance.addPostFrameCallback((_) => _reportSurfaceSize());
                            ^^^^^^^^^^^^^^^^^^^^
Failed to compile application.

Not sure what's going on here.

The project itself is not null-safe, but as far as I know it should still be possible to use null safe plugins?

Note that the error message points to webview_windows, but this is a Flutter Web project.

magnuswikhog avatar Jun 07 '22 12:06 magnuswikhog

I have this error too using easy_web_view 1.6.0. I am ONLY compiling for web. No windows, ios, android app etc. Why is it referring to webview_windows?? I am also running with unsound null safety as I am in the middle of updating an old project to null safety.

icecandy avatar Jun 08 '22 16:06 icecandy

I have just updated my project to null safety and I still have the same problem. PS using flutter version 2.10.3

icecandy avatar Jun 09 '22 10:06 icecandy

Hi @magnuswikhog @icecandy This is an issue with flutter 3 kindly downgrade the easy web view plugin or better still migrate the project to null safety and modify your code to this

WidgetsBinding.instance!.addPostFrameCallback((_) => _reportSurfaceSize());

Yczar avatar Jun 18 '22 21:06 Yczar

@Yczar Not sure if I understand you correctly - I got the error on Flutter 2.8.1...

magnuswikhog avatar Jun 18 '22 21:06 magnuswikhog