flutter_chips_choice icon indicating copy to clipboard operation
flutter_chips_choice copied to clipboard

Error: Method 'addPostFrameCallback' cannot be called on 'WidgetsBinding?'

Open arnabonetraker opened this issue 3 years ago • 0 comments

This package is giving this error during build.

Error: Method 'addPostFrameCallback' cannot be called on 'WidgetsBinding?' because it is potentially null.
 - 'WidgetsBinding' is from 'package:flutter/src/widgets/binding.dart' ('../../Development/flutter/packages/flutter/lib/src/widgets/binding.dart').
Try calling using ?. instead.
    WidgetsBinding.instance.addPostFrameCallback((_) {
                            ^^^^^^^^^^^^^^^^^^^^


FAILURE: Build failed with an exception.

Changing WidgetsBinding.instance.addPostFrameCallback to WidgetsBinding.instance?.addPostFrameCallback solves the issue.

flutter doctor

[✓] Flutter (Channel stable, 2.10.5, on macOS 12.6 21G115 darwin-x64, locale en-IN)
[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.0)
[✓] Xcode - develop for iOS and macOS (Xcode 14.0)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2021.2)
[✓] VS Code (version 1.71.2)
[✓] Connected device (2 available)
[✓] HTTP Host Availability

arnabonetraker avatar Sep 30 '22 10:09 arnabonetraker