EdsonBueno / infinite_scroll_pagination

Flutter package to help you lazily load and display pages of items as the user scrolls down your screen.
https://pub.dev/packages/infinite_scroll_pagination
MIT License
623 stars 210 forks source link

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

Closed insinfo closed 1 year ago

insinfo commented 2 years ago

I'm getting this error in Flutter 2.10.4


flutter --version
Flutter 2.10.4 • channel stable • https://github.com/flutter/flutter.git
Framework • revision c860cba910 (3 months ago) • 2022-03-25 00:23:12 -0500
Engine • revision 57d3bac3dd
Tools • Dart 2.16.2 • DevTools 2.9.2

PS C:\MyDartProjects\appjazz\appjazzmobile> flutter run        
Using hardware rendering with device sdk gphone x86 64. If you notice graphics artifacts, consider enabling software rendering with "--enable-software-rendering".
Launching lib\main.dart on sdk gphone x86 64 in debug mode...
/C:/src/flutter/.pub-cache/hosted/pub.dartlang.org/infinite_scroll_pagination-3.2.0/lib/src/ui/paged_sliver_builder.dart:254:33: Error: Method 'addPostFrameCallback' cannot be called on 'WidgetsBinding?' because it is potentially null.
 - 'WidgetsBinding' is from 'package:flutter/src/widgets/binding.dart' ('/C:/src/flutter/packages/flutter/lib/src/widgets/binding.dart').
Try calling using ?. instead.
        WidgetsBinding.instance.addPostFrameCallback((_) {
                                ^^^^^^^^^^^^^^^^^^^^

FAILURE: Build failed with an exception.

* Where:
Script 'C:\src\flutter\packages\flutter_tools\gradle\flutter.gradle' line: 1102

* What went wrong:
Execution failed for task ':app:compileFlutterBuildDebug'.
> Process 'command 'C:\src\flutter\bin\flutter.bat'' finished with non-zero exit value 1

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 1m 30s
Running Gradle task 'assembleDebug'...                             91,8s
Exception: Gradle task assembleDebug failed with exit code 1
PS C:\MyDartProjects\appjazz\appjazzmobile> 
name: appjazz
description: Aplicativo do Jazz e Blues
version: 9.0.3+15
publish_to: none

environment:
  sdk: ">=2.10.0 <3.0.0"

dependencies:
  flutter:
    sdk: flutter
  flutter_localizations:
    sdk: flutter

  #cupertino_icons: ^0.1.3 #Null safety 
  #http: ^0.13.4 #Null safety full
  dio_http_cache: ^0.3.0 #Null safety
  dio: ^4.0.4 #Null safety
  path_provider: ^2.0.8 #Null safety  full
  #sqflite: ^2.0.1 #Null safety 
  #connectivity_plus: ^2.1.0 #Null safety 
  url_launcher: ^6.0.17 #Null safety full

  firebase_core: ^1.10.5 #Null safety
  cloud_firestore: ^3.1.4 #Null safety
  firebase_auth: ^3.3.3 #Null safety
  #google_sign_in: ^5.2.1 #Null safety 
  #firebase_analytics: ^9.0.3 #Null safety 
  firebase_messaging: ^11.2.3 #Null safety

  rxdart: ^0.27.3 #Null safety full
  webview_flutter: ^3.0.0 #Null safety 
  auto_size_text: ^3.0.0 #Null safety full
  flutter_map: ^0.14.0 #Null safety full
  shared_preferences: ^2.0.10 #Null safety full
  latlong2: ^0.8.1 #Null safety full     
  share: ^2.0.4 #Null safety
  map_launcher: ^2.1.1  #Null safety
  #sticky_grouped_list: ^2.0.0-nullsafety.2  #Null safety
  #scrollable_positioned_list: ^0.2.0-nullsafety.0
  grouped_list: ^4.1.0 #Null safety
  carousel_slider: ^4.0.0 #Null safety
  #lightbox: ^0.1.0 #Null safety
  infinite_scroll_pagination: ^3.1.0  #Null safety
  cached_network_image: ^3.2.0 #Null safety

  #flutter_advanced_networkimage_2: ^2.0.1
  #flutter_advanced_networkimage_2:
  #  path: ../../flutter_advanced_networkimage

  turismo_core:
    path: ../../portal_turismo/turismo_core

dev_dependencies:
  flutter_test:
    sdk: flutter

  #intl_translation: ^0.17.7
  flutter_native_splash: ^1.3.2
  #run flutter pub run flutter_native_splash:create

flutter:
  uses-material-design: true

  assets:
    - assets/imagens/  

  fonts:
     - family: Antonio
       fonts:
         - asset: assets/fonts/Antonio-Regular.ttf
     - family: Big Noodle Titling
       fonts:
         - asset: assets/fonts/big_noodle_titling.ttf
     - family: GlosaDisplayW01-Bold
       fonts:
         - asset: assets/fonts/glosa_display_w01_bold.ttf
     - family: BakerieSmoothCondensedMedium
       fonts:
         - asset: assets/fonts/BakerieSmoothCondensed-Medium.otf
     - family: BakerieSmoothBold
       fonts:
         - asset: assets/fonts/BakerieSmooth-Bold.otf
     - family: iconsmind
       fonts:
         - asset: assets/fonts/iconsmind.ttf         
Rosco89 commented 2 years ago

Same here.

GuruJohn commented 2 years ago

Try reverting to version 3.1.0. It is a warning/error that will need to be fixed. Check offical release for flutter 3 here: https://docs.flutter.dev/development/tools/sdk/release-notes/release-notes-3.0.0#if-you-see-warnings-about-bindings

igor-chernishenko commented 2 years ago

Try reverting to version 3.1.0. It is a warning/error that will need to be fixed. Check offical release for flutter 3 here: https://docs.flutter.dev/development/tools/sdk/release-notes/release-notes-3.0.0#if-you-see-warnings-about-bindings

It is already fixed in 3.2.0, just need to update Flutter to 3.0

amir-7979 commented 2 years ago

go to file : 'flutter_path'\flutter.pub-cache\hosted\pub.dartlang.org\infinite_scroll_pagination-3.2.0\lib\src\ui\paged_sliver_builder.dart line 254 change WidgetsBinding.instance.addPostFrameCallback... to WidgetsBinding.instance?.addPostFrameCallback...

Freyien commented 2 years ago

Same here, I installed 3.1.0 version because I use Flutter 2.10.5.

Im not ready for Flutter 3

RukshanJS commented 2 years ago

Same here, I installed 3.1.0 version because I use Flutter 2.10.5.

Im not ready for Flutter 3

I would also really appreciate a stable fix for Flutter 2 (mine 2.5.2). Don't want to change pub cache every time after running flutter clean 🙃

clragon commented 2 years ago

the fix is to simply not upgrade to 3.2.0. the only change in 3.2.0 is the upgrade to flutter 3. if you are not ready for flutter 3, then use 3.1.0

RukshanJS commented 1 year ago

the fix is to simply not upgrade to 3.2.0. the only change in 3.2.0 is the upgrade to flutter 3. if you are not ready for flutter 3, then use 3.1.0

Have you tested this solution with Flutter 2? I tested with 2.5.2 and 2.10.5 versions but still the same error.

RukshanJS commented 1 year ago

Same here, I installed 3.1.0 version because I use Flutter 2.10.5.

Im not ready for Flutter 3

Did the 3.1.0 version work with Flutter 2.10.5 without any issue? I'm still getting same error.

RukshanJS commented 1 year ago

UPDATE : I got the setup working with Flutter 2.10.5 and version 3.1.0.

The issue I faced: I was putting infinite_scroll_pagination: ^3.1.0 in pubspec.yaml and "The ^ symbol before the version number means that you allow any compatible version of the package that is greater than or equal to 3.1.0", so the flutter pub get command acutally installed the 3.2.0 version. So I had to put infinite_scroll_pagination: 3.1.0 to use the exact version of the package and this solved the issue.

I suggest if you are having the same problem, first run flutter clean then flutter pub get then flutter run