微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

将 flutter 项目升级到 null-safety

如何解决将 flutter 项目升级到 null-safety

我的应用现在在 Flutter SDK 1.22.6 上运行,这是我的 pubspec.yaml

name: random-app
description: just random app.

# The following line prevents the package from being accidentally published to
# pub.dev using `pub publish`. This is preferred for private packages.
publish_to: 'none' # Remove this line if you wish to publish to pub.dev

# The following defines the version and build number for your application.
# A version number is three numbers separated by dots,like 1.2.43
# followed by an optional build number separated by a +.
# Both the version and the builder number may be overridden in Flutter
# build by specifying --build-name and --build-number,respectively.
# In Android,build-name is used as versionName while build-number used as versionCode.
# Read more about Android versioning at https://developer.android.com/studio/publish/versioning
# In iOS,build-name is used as CFBundleShortVersionString while build-number used as CFBundLeversion.
# Read more about iOS versioning at
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
version: 1.0.0+1

environment:
  sdk: ">=2.8.3 <3.0.0"
  Flutter: ^1.20.0

dependencies:
  Flutter:
    sdk: Flutter
  google_mobile_ads: ^0.11.0
  firebase_core: ^0.7.0
  circular_reveal_animation: ^1.1.5

  Flutter_localizations:
    sdk: Flutter


  # The following adds the Cupertino Icons font to your application.
  # Use with the CupertinoIcons class for iOS style icons.
  dartx: ^0.5.0
  cupertino_icons:
  shared_preferences:
  uuid:
  Flutter_router:
  font_awesome_Flutter:
  firebase_auth: ^0.20.1
  google_sign_in: ^4.5.9
  firebase_storage: ^7.0.0
  cloud_firestore: ^0.16.0+1 
  provider: ^4.3.3
  intl:
  geocoding: ^1.0.5
  geolocator: ^6.2.1
  chewie: ^0.12.2
  Flutter_absolute_path: ^1.0.6
  Flutter_spinkit: ^4.1.2+1
  Flutter_auth_buttons:
  find_dropdown: ^0.2.3 
  intl_phone_number_input: ^0.6.0
  carousel_slider: ^3.0.0
  jiffy: ^3.0.1
  timeago: ^2.0.30
  custom_switch: ^0.0.1
  expandable_text: ^1.3.2
  Flutter_typeahead: ^2.0.0  
  sliding_card: 0.1.2
  cached_network_image: ^2.5.1
  Flutter_svg: ^0.19.1
  url_launcher: ^5.7.10
  Flutter_easyloading: ^2.2.2
  Flutter_local_notifications: ^4.0.1+2
  scrollable_positioned_list: ^0.1.10
  http: ^0.12.2
  file_picker: ^2.1.7
  connectivity: ^2.0.2
  Flutter_colorpicker: ^0.3.5

  
 #for the assets picker 
  wechat_assets_picker: ^4.2.2
  wechat_camera_picker: ^1.3.1
  camera: ^0.5.8
  device_info: ^1.0.0
  assets_audio_player: ^2.0.13+1 
  extended_image: ^1.1.2
  path_provider: ^1.6.28
  photo_manager: ^0.5.8
  video_player: ^1.0.1
  collection: ^1.14.13
  #for posting gigs
  async: ^2.4.2
  get_it: ^5.0.6
  provider_architecture: ^1.1.1+1
  screenshot: ^0.3.0
  pull_to_refresh: 1.6.3



dev_dependencies:

  Flutter_test:
    sdk: Flutter
  
  Flutter_asset_generator: ^0.6.1

  Flutter_native_splash: ^0.3.2

Flutter_native_splash:
  image: assets/images/splash.png
  android: true
  ios: true
  android_gravity: fill
  ios_content_mode: sclaeAspectFill



# 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:
    - assets/images/
    - assets/svgs/light/
    - assets/svgs/solid/
    - assets/svgs/regular/
    - assets/svgs/flaticon/
    - languages/

  # 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

将我的 Flutter SDK 升级2.0.0 并在终端中运行以下命令后:

Flutter pub outdated --mode=null-safety

为了检查我是否可以升级我的依赖项,我在终端中得到了这个:

Package Name                 Current               Upgradable  Resolvable  Latest               

direct dependencies:        
assets_audio_player          ✗2.0.13+1             -           -           ✓3.0.3+6             
async                        ✗2.5.0-nullsafety.1   -           -           ✓2.8.1               
cached_network_image         ✗2.5.1                -           -           ✓3.1.0               
camera                       ✗0.5.8+17             -           -           ✓0.8.1+5             
carousel_slider              ✗3.0.0                -           -           ✓4.0.0               
chewie                       ✗0.12.2               -           -           ✓1.2.2               
circular_reveal_animation    ✗1.1.5                -           -           ✓2.0.0               
cloud_firestore              ✗0.16.0+1             -           -           ✓2.4.0               
collection                   ✗1.15.0-nullsafety.3  -           -           ✓1.15.0              
connectivity                 ✗2.0.2                -           -           ✓3.0.6               
cupertino_icons              ✗1.0.0                -           -           ✓1.0.3               
custom_switch                ✗0.0.1                -           -           ✗0.0.1               
dartx                        ✗0.5.0                -           -           ✓0.7.1               
device_info                  ✗1.0.0                -           -           ✓2.0.2               
expandable_text              ✗1.3.2                -           -           ✓2.2.0               
extended_image               ✗1.6.0                -           -           ✓4.1.0               
file_picker                  ✗2.1.7                -           -           ✓3.0.3               
find_dropdown                ✗0.2.3                -           -           ✓1.0.1-beta.2        
firebase_auth                ✗0.20.1               -           -           ✓3.0.1               
firebase_core                ✗0.7.0                -           -           ✓1.4.0               
firebase_storage             ✗7.0.0                -           -           ✓10.0.1              
Flutter_absolute_path        ✗1.0.6                -           -           ✗1.0.6               
Flutter_auth_buttons         ✗0.10.0               -           -           ✗0.10.0              
Flutter_colorpicker          ✗0.3.5                -           -           ✓0.5.0               
Flutter_easyloading          ✗2.2.2                -           -           ✓3.0.0               
Flutter_local_notifications  ✗4.0.1+2              -           -           ✓7.0.0               
Flutter_router               ✗1.0.7                -           -           ✓1.1.0               
Flutter_spinkit              ✗4.1.2+1              -           -           ✓5.0.0               
Flutter_svg                  ✗0.19.1               -           -           ✓0.22.0              
Flutter_typeahead            ✗2.0.0                -           -           ✓3.2.0               
font_awesome_Flutter         ✗8.12.0               -           -           ✓9.1.0               
geocoding                    ✗1.0.5                -           -           ✓2.0.0               
geolocator                   ✗6.2.1                -           -           ✓7.3.1               
get_it                       ✗5.0.6                -           -           ✓7.2.0               
google_mobile_ads            ✗0.11.0+4             -           -           ✓0.13.2              
google_sign_in               ✗4.5.9                -           -           ✓5.0.5               
http                         ✗0.12.2               -           -           ✓0.13.3              
intl                         ✗0.16.1               -           -           ✓0.17.0              
intl_phone_number_input      ✗0.6.0                -           -           ✓0.7.0+2             
jiffy                        ✗3.0.1                -           -           ✓4.1.0               
path_provider                ✗1.6.28               -           -           ✓2.0.2               
photo_manager                ✗0.5.8                -           -           ✓1.2.8               
provider                     ✗4.3.3                -           -           ✓6.0.0-dev           
provider_architecture        ✗1.1.1+1              -           -           ✗1.1.1+1             
pull_to_refresh              ✗1.6.3                -           -           ✓2.0.0               
screenshot                   ✗0.3.0                -           -           ✓1.2.3               
scrollable_positioned_list   ✗0.1.10               -           -           ✓0.2.0-nullsafety.0  
shared_preferences           ✗0.5.12+4             -           -           ✓2.0.6               
sliding_card                 ✗0.1.2                -           -           ✗0.1.2               
timeago                      ✗2.0.30               -           -           ✓3.1.0               
url_launcher                 ✗5.7.10               -           -           ✓6.0.9               
uuid                         ✗2.2.2                -           -           ✓3.0.4               
video_player                 ✗1.0.1                -           -           ✓2.1.12              
wechat_assets_picker         ✗4.2.2                -           -           ✓6.0.0-dev.9         
wechat_camera_picker         ✗1.3.1                -           -           ✓2.3.0-dev.2         

dev_dependencies:           
Flutter_asset_generator      ✗0.6.1                -           -           ✓1.0.0-nullsafety.0  
Flutter_native_splash        ✗0.3.2                -           -           ✓1.2.0               
No resolution was found. Try running `Flutter pub upgrade --null-safety --dry-run` to explore why.

谁能告诉我为什么我在可解析列下看不到任何带有 ✓ 符号的包版本?

这是否意味着我不能同时迁移到空安全?

任何帮助将不胜感激。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。