从2.8.1升级到Flutter 3.0,得到:Warning: Operand of null-aware operation '?.' has type 'PaintingBinding' which excludes null error
它在binding.dart
上——一个我根本不碰的文件。
() => PaintingBinding.instance?.imageCache?.evict(key),
^
你们知道我怎么修吗?
不知道是否相关,但也经常看到这个:
Class 'kotlin.Unit' was compiled with an incompatible version
使用此处的指南进行迁移:https://github.com/flutter/flutter/wiki/Upgrading-pre-1.12-Android-projects
这是我的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
所以,有些东西帮助了我:
- 删除下一个文件夹/Users/your-user/.pub-cache/hosted/pub.dartlang.org
- hit
flutter pub upgrade
然后尝试运行您的项目🎉
对于那些有同样问题的人:更改我的Kotlin版本(手动),做到了这一点。
现在,在build.gradle:
buildscript {
ext.kotlin_version = '1.6.21'
repositories {
google()
jcenter()
}
我有这个而不是版本1.3.40
remove "?"at() => PaintingBinding.instance?.imageCache?.evict(key),