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

Missing Null Safety on WidgetsBinding & SchedulerBinding #21

Closed
Rishabh-Invizio opened this issue May 12, 2022 · 12 comments
Closed

Missing Null Safety on WidgetsBinding & SchedulerBinding #21

Rishabh-Invizio opened this issue May 12, 2022 · 12 comments
Assignees
Projects

Comments

@Rishabh-Invizio
Copy link

The image_editor_plus: ^0.1.3 package in our project, is using the latest version of nb_utils: 4.5.1.
Our Flutter project's environment sdk contraints are:

environment:
  sdk: ">=2.16.2 <3.0.0"

When building the app for Android, the build fails with the following error:

../../Flutter%20SDK/Flutter%20Git%20Repository/flutter/.pub-cache/hosted/pub.dartlang.org/nb_utils-4.5.1/lib/src/utils/common.dart:200:29: Error: Method 'addPostFrameCallback' cannot be called on 'SchedulerBinding?' because it is potentially null.
 - 'SchedulerBinding' is from 'package:flutter/src/scheduler/binding.dart' ('../../Flutter%20SDK/Flutter%20Git%20Repository/flutter/packages/flutter/lib/src/scheduler/binding.dart').
Try calling using ?. instead.
  SchedulerBinding.instance.addPostFrameCallback((_) => onCreated?.call());
                            ^^^^^^^^^^^^^^^^^^^^
../../Flutter%20SDK/Flutter%20Git%20Repository/flutter/.pub-cache/hosted/pub.dartlang.org/nb_utils-4.5.1/lib/src/utils/after_layout.dart:12:10: Error: Method 'addPostFrameCallback' cannot be called on 'WidgetsBinding?' because it is potentially null.
 - 'WidgetsBinding' is from 'package:flutter/src/widgets/binding.dart' ('../../Flutter%20SDK/Flutter%20Git%20Repository/flutter/packages/flutter/lib/src/widgets/binding.dart').
Try calling using ?. instead.
        .addPostFrameCallback((_) => afterFirstLayout(context));
         ^^^^^^^^^^^^^^^^^^^^
../../Flutter%20SDK/Flutter%20Git%20Repository/flutter/.pub-cache/hosted/pub.dartlang.org/nb_utils-4.5.1/lib/src/widgets/OverlayCustomWidget.dart:59:31: Error: Method 'addPostFrameCallback' cannot be called on 'WidgetsBinding?' because it is potentially null.
 - 'WidgetsBinding' is from 'package:flutter/src/widgets/binding.dart' ('../../Flutter%20SDK/Flutter%20Git%20Repository/flutter/packages/flutter/lib/src/widgets/binding.dart').
Try calling using ?. instead.
      WidgetsBinding.instance.addPostFrameCallback((_) => showOverlay());
                              ^^^^^^^^^^^^^^^^^^^^
../../Flutter%20SDK/Flutter%20Git%20Repository/flutter/.pub-cache/hosted/pub.dartlang.org/nb_utils-4.5.1/lib/src/widgets/OverlayCustomWidget.dart:66:29: Error: Method 'addPostFrameCallback' cannot be called on 'WidgetsBinding?' because it is potentially null.
 - 'WidgetsBinding' is from 'package:flutter/src/widgets/binding.dart' ('../../Flutter%20SDK/Flutter%20Git%20Repository/flutter/packages/flutter/lib/src/widgets/binding.dart').
Try calling using ?. instead.
    WidgetsBinding.instance.addPostFrameCallback((_) => syncWidgetAndOverlay());
                            ^^^^^^^^^^^^^^^^^^^^
../../Flutter%20SDK/Flutter%20Git%20Repository/flutter/.pub-cache/hosted/pub.dartlang.org/nb_utils-4.5.1/lib/src/widgets/OverlayCustomWidget.dart:72:29: Error: Method 'addPostFrameCallback' cannot be called on 'WidgetsBinding?' because it is potentially null.
 - 'WidgetsBinding' is from 'package:flutter/src/widgets/binding.dart' ('../../Flutter%20SDK/Flutter%20Git%20Repository/flutter/packages/flutter/lib/src/widgets/binding.dart').
Try calling using ?. instead.
    WidgetsBinding.instance.addPostFrameCallback((_) => syncWidgetAndOverlay());
                            ^^^^^^^^^^^^^^^^^^^^
../../Flutter%20SDK/Flutter%20Git%20Repository/flutter/.pub-cache/hosted/pub.dartlang.org/nb_utils-4.5.1/lib/src/widgets/TimerWidget.dart:44:29: Error: Method 'addObserver' cannot be called on 'WidgetsBinding?' because it is potentially null.
 - 'WidgetsBinding' is from 'package:flutter/src/widgets/binding.dart' ('../../Flutter%20SDK/Flutter%20Git%20Repository/flutter/packages/flutter/lib/src/widgets/binding.dart').
Try calling using ?. instead.
    WidgetsBinding.instance.addObserver(this);
                            ^^^^^^^^^^^
../../Flutter%20SDK/Flutter%20Git%20Repository/flutter/.pub-cache/hosted/pub.dartlang.org/nb_utils-4.5.1/lib/src/widgets/TimerWidget.dart:59:29: Error: Method 'removeObserver' cannot be called on 'WidgetsBinding?' because it is potentially null.
 - 'WidgetsBinding' is from 'package:flutter/src/widgets/binding.dart' ('../../Flutter%20SDK/Flutter%20Git%20Repository/flutter/packages/flutter/lib/src/widgets/binding.dart').
Try calling using ?. instead.
    WidgetsBinding.instance.removeObserver(this);
                            ^^^^^^^^^^^^^^


FAILURE: Build failed with an exception.

It seems you have missed null safety on WidgetsBinding and SchedulerBinding methods, causing the exception to be thrown. Can you get please provide a fix for this asap?

@BenCherif
Copy link

the same issue here :D

@bhoominn
Copy link
Owner

bhoominn commented May 12, 2022

You have to update for Flutter SDK version to 3.0.0.

Or you can use nb_utils version 4.5.0.

@heydc7
Copy link

heydc7 commented May 14, 2022

I am using Flutter 3.0, but still, it is giving the same errors.

@bhoominn
Copy link
Owner

bhoominn commented May 14, 2022

Please show errors here.

@heydc7
Copy link

heydc7 commented May 14, 2022

../../../Developer/flutter/.pub-cache/hosted/pub.dartlang.org/nb_utils-4.5.1/lib/src/widgets/TimerWidget.dart:44:20: Warning: Operand of null-aware operation '?.' has type 'WidgetsBinding' which excludes null.

  • 'WidgetsBinding' is from 'package:flutter/src/widgets/binding.dart' ('../../../Developer/flutter/packages/flutter/lib/src/widgets/binding.dart').
    WidgetsBinding.instance?.addObserver(this);
    ^
    ../../../Developer/flutter/.pub-cache/hosted/pub.dartlang.org/nb_utils-4.5.1/lib/src/widgets/TimerWidget.dart:59:20: Warning: Operand of null-aware operation '?.' has type 'WidgetsBinding' which excludes null.
  • 'WidgetsBinding' is from 'package:flutter/src/widgets/binding.dart' ('../../../Developer/flutter/packages/flutter/lib/src/widgets/binding.dart').
    WidgetsBinding.instance?.removeObserver(this);
    ^
    ../../../Developer/flutter/.pub-cache/hosted/pub.dartlang.org/nb_utils-4.5.1/lib/src/widgets/OverlayCustomWidget.dart:59:22: Warning: Operand of null-aware operation '?.' has type 'WidgetsBinding' which excludes null.
  • 'WidgetsBinding' is from 'package:flutter/src/widgets/binding.dart' ('../../../Developer/flutter/packages/flutter/lib/src/widgets/binding.dart').
    WidgetsBinding.instance?.addPostFrameCallback((_) => showOverlay());
    ^
    ../../../Developer/flutter/.pub-cache/hosted/pub.dartlang.org/nb_utils-4.5.1/lib/src/widgets/OverlayCustomWidget.dart:66:20: Warning: Operand of null-aware operation '?.' has type 'WidgetsBinding' which excludes null.
  • 'WidgetsBinding' is from 'package:flutter/src/widgets/binding.dart' ('../../../Developer/flutter/packages/flutter/lib/src/widgets/binding.dart').
    WidgetsBinding.instance?.addPostFrameCallback((_) => syncWidgetAndOverlay());
    ^
    ../../../Developer/flutter/.pub-cache/hosted/pub.dartlang.org/nb_utils-4.5.1/lib/src/widgets/OverlayCustomWidget.dart:72:20: Warning: Operand of null-aware operation '?.' has type 'WidgetsBinding' which excludes null.
  • 'WidgetsBinding' is from 'package:flutter/src/widgets/binding.dart' ('../../../Developer/flutter/packages/flutter/lib/src/widgets/binding.dart').
    WidgetsBinding.instance?.addPostFrameCallback((_) => syncWidgetAndOverlay());
    ^
    ../../../Developer/flutter/.pub-cache/hosted/pub.dartlang.org/nb_utils-4.5.1/lib/src/utils/common.dart:200:20: Warning: Operand of null-aware operation '?.' has type 'SchedulerBinding' which excludes null.
  • 'SchedulerBinding' is from 'package:flutter/src/scheduler/binding.dart' ('../../../Developer/flutter/packages/flutter/lib/src/scheduler/binding.dart').
    SchedulerBinding.instance?.addPostFrameCallback((_) => onCreated?.call());
    ^
    ../../../Developer/flutter/.pub-cache/hosted/pub.dartlang.org/nb_utils-4.5.1/lib/src/utils/after_layout.dart:11:20: Warning: Operand of null-aware operation '?.' has type 'WidgetsBinding' which excludes null.
  • 'WidgetsBinding' is from 'package:flutter/src/widgets/binding.dart' ('../../../Developer/flutter/packages/flutter/lib/src/widgets/binding.dart').
    WidgetsBinding.instance?.addPostFrameCallback((_) => afterFirstLayout(context));

@bhoominn
Copy link
Owner

Ok, show flutter doctor command output.

@heydc7
Copy link

heydc7 commented May 14, 2022

Screenshot 2022-05-14 at 16 12 47

@heydc7
Copy link

heydc7 commented May 14, 2022

(base) dhanraj@192 ytcards % flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.0.0, on macOS 12.3.1 21E258 darwin-x64, locale en-IN)
[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
[✓] Xcode - develop for iOS and macOS (Xcode 13.3.1)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2021.2)
[✓] VS Code (version 1.67.0)
[✓] Connected device (3 available)
! Error: Dhanraj’s iPhone is busy: Waiting to connect and unlock the device. Xcode will continue when Dhanraj’s iPhone is finished. (code -10)
! Error: iPad is not connected. Xcode will continue when iPad is connected. (code -13)
[✓] HTTP Host Availability

• No issues found!

@athulpp
Copy link

athulpp commented May 15, 2022

same error in my project also when implementing this package

@bhoominn
Copy link
Owner

Upgrade this package to the latest version 4.5.2 and check if your issue is solved or not.

@bhoominn bhoominn self-assigned this May 15, 2022
@heydc7
Copy link

heydc7 commented May 15, 2022

Yes, All errors are gone. Working smoothly ✨ Thank you!!!

@AlaaMarawi
Copy link

Upgrade this package to the latest version 4.5.2 and check if your issue is solved or not.

It is solved with v4.5.2 & flutter 2.8.1. but this means I can't use later versions :(

UPDATE: I upgraded to flutter 3 -> it is solved (in both 4.5.2 & the latest)

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

No branches or pull requests

6 participants