Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Method 'addPostFrameCallback' cannot be called on 'WidgetsBinding?' because it is potentially null. #12

Closed
greyovo opened this issue Jun 3, 2022 · 4 comments

Comments

@greyovo
Copy link

greyovo commented Jun 3, 2022

Error:

/F:/SDK/flutter_windows_2.10.5-stable/flutter/.pub-cache/hosted/pub.flutter-io.cn/another_xlider-1.1.0/lib/another_xlider.dart:441:29: Error: Method 'addPostFrameCallback' cannot be called on 'WidgetsBinding?' because it is potentially null.

  • 'WidgetsBinding' is from 'package:flutter/src/widgets/binding.dart' ('/F:/SDK/flutter_windows_2.10.5-stable/flutter/packages/flutter/lib/src/widgets/binding.dart').
    Try calling using ?. instead.
    WidgetsBinding.instance.addPostFrameCallback((_) {
    ^^^^^^^^^^^^^^^^^^^^
@greyovo
Copy link
Author

greyovo commented Jun 3, 2022

I added ? to instance and it works.

WidgetsBinding.instance?.addPostFrameCallback((_) {
      if (!mounted) {
        return;
      }
      _renderBoxInitialization();
      _arrangeHandlersPosition();
      _drawHatchMark();
      setState(() {});
});

@loonix
Copy link
Owner

loonix commented Jun 8, 2022

#9

Changes were made to clear this issue, should be on the latest version

@loonix loonix closed this as completed Jun 8, 2022
@greyovo
Copy link
Author

greyovo commented Jul 20, 2022

@loonix It's giving the same error on 1.1.2. I need to modify it manually.

@loonix
Copy link
Owner

loonix commented Jul 20, 2022

It will give you error if you are using flutter 2. Upgrade to v3 and check

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants