'Upgraded to Flutter 3.0 from 2.8.1, getting: Warning: Operand of null-aware operation '?.' has type 'PaintingBinding' which excludes null error
Upgraded to Flutter 3.0 from 2.8.1, getting: Warning: Operand of null-aware operation '?.' has type 'PaintingBinding' which excludes null error
It's on binding.dart
- a file I don't touch at all.
() => PaintingBinding.instance?.imageCache?.evict(key),
^
Any chance you guys know how I can fix it?
Don't know if related, but also seeing this a lot:
Class 'kotlin.Unit' was compiled with an incompatible version
Used the guide here to migrate: https://github.com/flutter/flutter/wiki/Upgrading-pre-1.12-Android-projects
This is my pubspec:
environment:
sdk: '>=2.12.0 <3.0.0'
dependencies:
flutter:
sdk: flutter
flutter_localizations:
sdk: flutter
google_maps_flutter: ^2.0.6
rxdart:
shimmer:
cupertino_icons: ^1.0.3
dependencies:
flutter_svg: ^1.0.0
http: ^0.13.3
flutter_spinkit: ^5.0.0
url_launcher: ^6.0.9
html: ^0.15.0
cached_network_image: ^3.1.0
collection: ^1.15.0
share_plus: ^3.0.4
flutter_native_splash: ^1.3.2
dev_dependencies:
flutter_test:
sdk: flutter
flutter_launcher_icons: ^0.9.2
flutter_icons:
android: true
ios: true
image_path: "assets/app/launch/ic_launcher.png"
adaptive_icon_padding: true
# For information on the generic Dart part of this file, see the
# following page: https://dart.dev/tools/pub/pubspec
# The following section is specific to Flutter.
flutter:
# The following line ensures that the Material Icons font is
# included with your application, so that you can use the icons in
# the material Icons class.
uses-material-design: true
# To add assets to your application, add an assets section, like this:
# assets:
# - images/a_dot_burr.jpeg
# - images/a_dot_ham.jpeg
# An image asset can refer to one or more resolution-specific "variants", see
# https://flutter.dev/assets-and-images/#resolution-aware.
# For details regarding adding assets from package dependencies, see
# https://flutter.dev/assets-and-images/#from-packages
# To add custom fonts to your application, add a fonts section here,
# in this "flutter" section. Each entry in this list should have a
# "family" key with the font family name, and a "fonts" key with a
# list giving the asset and other descriptors for the font. For
# example:
# fonts:
# - family: Schyler
# fonts:
# - asset: fonts/Schyler-Regular.ttf
# - asset: fonts/Schyler-Italic.ttf
# style: italic
# - family: Trajan Pro
# fonts:
# - asset: fonts/TrajanPro.ttf
# - asset: fonts/TrajanPro_Bold.ttf
# weight: 700
#
# For details regarding fonts from package dependencies,
# see https://flutter.dev/custom-fonts/#from-packages
Solution 1:[1]
So, something which helped me:
- remove the next folder /Users/your-user/.pub-cache/hosted/pub.dartlang.org
- hit
flutter pub upgrade
and then try to run your project ?
Solution 2:[2]
For the ones that have the same issue: changing my Kotlin version (manually), did the trick.
Now, in build.gradle:
buildscript {
ext.kotlin_version = '1.6.21'
repositories {
google()
jcenter()
}
I have this instead of version 1.3.40
Solution 3:[3]
remove "?" at () => PaintingBinding.instance?.imageCache?.evict(key),
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 | Andriy Antonov |
Solution 2 | Johan |
Solution 3 | Saitoh Akira |