5

我将颤振 sdk 升级到颤振 2.0.0。更新 sdk 后,我已将几乎所有库更改为空安全版本:

environment:
  sdk: '>=2.12.0 <3.0.0'

dependencies:
  flutter:
    sdk: flutter
  flutter_localizations:
    sdk: flutter 
  cupertino_icons: ^0.1.3
  encrypt: ^4.1.0
  flutter_hooks: ^0.15.0
  flutter_map: ^0.11.0
  flutter_password_strength: ^0.1.5
  flutter_svg: ^0.18.0
  geolocator: ^7.0.1
  get: ^3.25.6
  get_it: ^6.0.0
  injectable: ^1.1.2
  local_auth: ^1.1.0
  moor_flutter: ^3.1.0
  provider: ^5.0.0
  shared_preferences: ^2.0.3
  supercharged: ^1.12.0
  intl: ^0.17.0

更新后我运行 dart$ dart migrate命令。但它显示了有关 intl 插件的这些问题:

Analyzing project...
[---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------/]
5 analysis issues found:
  error • A value of type 'Null' can't be returned from the function '_findExact' because it has a return type of 'MessageLookupByLibrary' at lib/generated/intl/messages_all.dart:34:14 • (return_of_invalid_type)
  error • A value of type 'Null' can't be returned from the function '_findGeneratedMessagesFor' because it has a return type of 'MessageLookupByLibrary' at lib/generated/intl/messages_all.dart:65:36 • (return_of_invalid_type)
  error • Non-nullable instance field 'current' must be initialized at lib/generated/l10n.dart:16:3 • (not_initialized_non_nullable_instance_field)
  error • The non-nullable variable 'current' must be initialized at lib/generated/l10n.dart:18:12 • (not_initialized_non_nullable_variable)
  error • A value of type 'S?' can't be returned from the method 'of' because it has a return type of 'S' at lib/generated/l10n.dart:35:12 • (return_of_invalid_type)

The migration tool didn't start, due to analysis errors.

在此处输入图像描述

在此处输入图像描述

我正在使用最新版本的 intl ?我该如何解决?

Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 2.0.0, on Linux, locale en_US.UTF-8)
[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.0-rc1)
[✓] Chrome - develop for the web
[✓] Android Studio (version 4.0)
[✓] VS Code (version 1.53.2)
[✓] Connected device (2 available)

• No issues found!
4

1 回答 1

1

我遇到过同样的问题。以下是解决此问题的 3 个步骤:

  1. 首先,将intl依赖项更新pubspec.yaml为此:

    国际:0.17.0-nullsafety.2

  2. 如果仍然不起作用,则在根目录中添加这两个字段。

    依赖覆盖:国际:0.17.0-nullsafety.2

  3. 生成也可以通过 Android Studio 中的插件进行。我使用了旧版本(v 0.12),在我更新到(v 0.14)之后,它开始生成空安全 dart 文件以进行本地化。

我想我踩到了这里的每一块石头。

于 2021-06-10T19:58:19.330 回答