DavideBelsole / great_list_view

pub.dev library for flutter
MIT License
41 stars 22 forks source link

Flutter 3: "Warning: Operand of null-aware operation '!' has type 'WidgetsBinding' which excludes null." #21

Closed mregnauld closed 1 year ago

mregnauld commented 2 years ago

In my Flutter project, I just upgraded to Flutter 3, and now, when I compile my app, I get the following warnings:

../../../FlutterSDK/flutter/.pub-cache/hosted/pub.dartlang.org/great_list_view-0.1.4/lib/src/core/sliver_list.dart:29:24: Warning: Operand of null-aware operation '?.' has type 'WidgetsBinding' which excludes null.
 - 'WidgetsBinding' is from 'package:flutter/src/widgets/binding.dart' ('../../../FlutterSDK/flutter/packages/flutter/lib/src/widgets/binding.dart').
    if (WidgetsBinding.instance?.schedulerPhase ==
                       ^
../../../FlutterSDK/flutter/.pub-cache/hosted/pub.dartlang.org/great_list_view-0.1.4/lib/src/core/sliver_list.dart:31:22: Warning: Operand of null-aware operation '?.' has type 'WidgetsBinding' which excludes null.
 - 'WidgetsBinding' is from 'package:flutter/src/widgets/binding.dart' ('../../../FlutterSDK/flutter/packages/flutter/lib/src/widgets/binding.dart').
      WidgetsBinding.instance?.addPostFrameCallback((_) => markNeedsLayout());
                     ^
../../../FlutterSDK/flutter/.pub-cache/hosted/pub.dartlang.org/great_list_view-0.1.4/lib/src/core/sliver_list.dart:171:22: Warning: Operand of null-aware operation '?.' has type 'WidgetsBinding' which excludes null.
 - 'WidgetsBinding' is from 'package:flutter/src/widgets/binding.dart' ('../../../FlutterSDK/flutter/packages/flutter/lib/src/widgets/binding.dart').
      WidgetsBinding.instance?.addPostFrameCallback((_) {
                     ^
../../../FlutterSDK/flutter/.pub-cache/hosted/pub.dartlang.org/great_list_view-0.1.4/lib/src/core/sliver_list.dart:491:20: Warning: Operand of null-aware operation '!' has type 'WidgetsBinding' which excludes null.
 - 'WidgetsBinding' is from 'package:flutter/src/widgets/binding.dart' ('../../../FlutterSDK/flutter/packages/flutter/lib/src/widgets/binding.dart').
    WidgetsBinding.instance!.addPostFrameCallback((_) {
                   ^
../../../FlutterSDK/flutter/.pub-cache/hosted/pub.dartlang.org/great_list_view-0.1.4/lib/src/core/sliver_list.dart:510:24: Warning: Operand of null-aware operation '!' has type 'WidgetsBinding' which excludes null.
 - 'WidgetsBinding' is from 'package:flutter/src/widgets/binding.dart' ('../../../FlutterSDK/flutter/packages/flutter/lib/src/widgets/binding.dart').
        WidgetsBinding.instance!.addPostFrameCallback((_) {
                       ^

And here is my flutter doctor -v output:

[✓] Flutter (Channel stable, 3.0.2, on macOS 11.3.1 20E241 darwin-arm, locale fr-FR)
    • Flutter version 3.0.2 at /Users/mregnauld/FlutterSDK/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision cd41fdd495 (4 days ago), 2022-06-08 09:52:13 -0700
    • Engine revision f15f824b57
    • Dart version 2.17.3
    • DevTools version 2.12.2

[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.0-rc1)
    • Android SDK at /Users/mregnauld/AndroidSDK
    • Platform android-32, build-tools 33.0.0-rc1
    • ANDROID_HOME = /Users/mregnauld/AndroidSDK
    • Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 11.0.12+0-b1504.28-7817840)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 13.2.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • CocoaPods version 1.11.2

[✗] Chrome - develop for the web (Cannot find Chrome executable at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome)
    ! Cannot find Chrome. Try setting CHROME_EXECUTABLE to a Chrome executable.

[✓] Android Studio (version 2021.2)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 11.0.12+0-b1504.28-7817840)

[✓] VS Code (version 1.57.1)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.24.0

[✓] Connected device (2 available)
    • SM M515F (mobile) • RF8NC0PSMMV • android-arm64 • Android 12 (API 31)
    • macOS (desktop)   • macos       • darwin-arm64  • macOS 11.3.1 20E241 darwin-arm
    ! Error: Failed to prepare device for development. Please unlock and reconnect the device. (code 806)

[✓] HTTP Host Availability
    • All required HTTP hosts are available

! Doctor found issues in 1 category.

Did I miss something, or could it be fixed soon?

Thanks.

bitbeter commented 2 years ago

We have same issue with in flutter 3

rupinderjeet commented 2 years ago

I have a fork on this change in fix/widgetsbindinginstance branch. But, you may want to go through the 3 commits I made (to be aware of what I changed) before using it.

https://github.com/rupinderjeet/great_list_view/tree/fix/widgetsbindinginstance

DavideBelsole commented 1 year ago

try the new version 0.2.0

mregnauld commented 1 year ago

It works now, thanks!