'Execution failed for task ':app:compileFlutterBuildDebug'. > Process 'command 'C:\FlutterSdk\flutter\bin\flutter.bat'

/C:/FlutterSdk/flutter/.pub-cache/hosted/pub.dartlang.org/fl_chart-0.50.5/lib/src/chart/pie_chart/pie_chart.dart:42:29: Error: Method 'addPostFrameCallback' cannot be called on 'WidgetsBinding?' because it is potentially null.

  • 'WidgetsBinding' is from 'package:flutter/src/widgets/binding.dart' ('/C:/FlutterSdk/flutter/packages/flutter/lib/src/widgets/binding.dart'). Try calling using ?. instead. WidgetsBinding.instance.addPostFrameCallback((_) { ^^^^^^^^^^^^^^^^^^^^

FAILURE: Build failed with an exception.

  • Where: Script 'C:\FlutterSdk\flutter\packages\flutter_tools\gradle\flutter.gradle' line: 1102

  • What went wrong: Execution failed for task ':app:compileFlutterBuildDebug'.

Process 'command 'C:\FlutterSdk\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 33s Running Gradle task 'assembleDebug'... 38.2s Exception: Gradle task assembleDebug failed with exit code 1



Solution 1:[1]

lib provider had breaking changes when migrating to flutter 3 but didn't bump the major version, you can try locking the version in pubspec.yml or migrate to flutter 3 as well...

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 wocesev