Flutter @Error:此库禁用了空安全功能

M A*_*Rao 24 ios dart flutter

我正在构建一个 Flutter 应用程序,当我为 Android 构建应用程序时,该应用程序达到了标记,但是当我开始为 iOS 构建应用程序时,我开始面临“此库已禁用空安全功能”的错误

错误如下:

Users/himanshu/.pub-cache/hosted/pub.dartlang.org/path-1.8.0-nullsafety/lib/path.dart:100:4: Error: Null safety features are disabled for this library.
Try removing the package language version or setting the language version to 2.10 or higher.
Uri? _currentUriBase;
   ^
/Users/himanshu/.pub-cache/hosted/pub.dartlang.org/path-1.8.0-nullsafety/lib/path.dart:106:7: Error: Null safety features are disabled for this library.
Try removing the package language version or setting the language version to 2.10 or higher.
String? _current;
      ^
/Users/himanshu/.pub-cache/hosted/pub.dartlang.org/path-1.8.0-nullsafety/lib/path.dart:120:16: Error: Null safety features are disabled for this library.
Try removing the package language version or setting the language version to 2.10 or higher.
        [String? part2,
               ^
/Users/himanshu/.pub-cache/hosted/pub.dartlang.org/path-1.8.0-nullsafety/lib/path.dart:121:15: Error: Null safety features are disabled for this library.
Try removing the package language version or setting the language version to 2.10 or higher.
        String? part3,
              ^
/Users/himanshu/.pub-cache/hosted/pub.dartlang.org/path-1.8.0-nullsafety/lib/path.dart:122:15: Error: Null safety features are disabled for this library.
Try removing the package language version or setting the language version to 2.10 or higher.
        String? part4,
              ^
/Users/himanshu/.pub-cache/hosted/pub.dartlang.org/path-1.8.0-nullsafety/lib/path.dart:123:15: Error: Null safety features are disabled for this library.
Try removing the package language version or setting the language version to 2.10 or higher.
        String? part5,
              ^
/Users/himanshu/.pub-cache/hosted/pub.dartlang.org/path-1.8.0-nullsafety/lib/path.dart:124:15: Error: Null safety features are disabled for this library.
Try removing the package language version or setting the language version to 2.10 or higher.
        String? part6,
              ^
/Users/himanshu/.pub-cache/hosted/pub.dartlang.org/path-1.8.0-nullsafety/lib/path.dart:125:15: Error: Null safety features are disabled for this library.
Try removing the package language version or setting the language version to 2.10 or higher.
        String? part7]) =>
              ^
/Users/himanshu/.pub-cache/hosted/pub.dartlang.org/path-1.8.0-nullsafety/lib/path.dart:258:16: Error: Null safety features are disabled for this library.
Try removing the package language version or setting the language version to 2.10 or higher.
        [String? part2,
               ^
/Users/himanshu/.pub-cache/hosted/pub.dartlang.org/path-1.8.0-nullsafety/lib/path.dart:259:15: Error: Null safety features are disabled for this library.
Try removing the package language version or setting the language version to 2.10 or higher.
        String? part3,
              ^
/Users/himanshu/.pub-cache/hosted/pub.dartlang.org/path-1.8.0-nullsafety/lib/path.dart:260:15: Error: Null safety features are disabled for this library.
Try removing the package language version or setting the language version to 2.10 or higher.
        String? part4,
              ^
/Users/himanshu/.pub-cache/hosted/pub.dartlang.org/path-1.8.0-nullsafety/lib/path.dart:261:15: Error: Null safety features are disabled for this library.
Try removing the package language version or setting the language version to 2.10 or higher.
        String? part5,
              ^
/Users/himanshu/.pub-cache/hosted/pub.dartlang.org/path-1.8.0-nullsafety/lib/path.dart:262:15: Error: Null safety features are disabled for this library.
Try removing the package language version or setting the language version to 2.10 or higher.
        String? part6,
              ^
/Users/himanshu/.pub-cache/hosted/pub.dartlang.org/path-1.8.0-nullsafety/lib/path.dart:263:15: Error: Null safety features are disabled for this library.
Try removing the package language version or setting the language version to 2.10 or higher.
        String? part7,
              ^
/Users/himanshu/.pub-cache/hosted/pub.dartlang.org/path-1.8.0-nullsafety/lib/path.dart:264:15: Error: Null safety features are disabled for this library.
Try removing the package language version or setting the language version to 2.10 or higher.
        String? part8]) =>
              ^
/Users/himanshu/.pub-cache/hosted/pub.dartlang.org/path-1.8.0-nullsafety/lib/path.dart:358:37: Error: Null safety features are disabled for this library.
Try removing the package language version or setting the language version to 2.10 or higher.
String relative(String path, {String? from}) =>
                                    ^
/Users/himanshu/flutter/packages/flutter/lib/src/widgets/actions.dart:126:9: Error: Null safety features are disabled for this library.
Try removing the package language version or setting the language version to 2.10 or higher.
  Object? invoke(covariant T intent);
        ^
/Users/himanshu/flutter/packages/flutter/lib/src/widgets/actions.dart:235:8: Error: Null safety features are disabled for this library.
Try removing the package language version or setting the language version to 2.10 or higher.
    Key? key,
       ^
/Users/himanshu/flutter/packages/flutter/lib/src/widgets/actions.dart:330:50: Error: Null safety features are disabled for this library.
Try removing the package language version or setting the language version to 2.10 or higher.
  Object invoke(covariant T intent, [BuildContext? context]);
                                                 ^
/Users/himanshu/flutter/packages/flutter/lib/src/widgets/actions.dart:334:52: Error: Null safety features are disabled for this library.
Try removing the package language version or setting the language version to 2.10 or higher.
typedef OnInvokeCallback<T extends Intent> = Object? Function(T intent);
                                                   ^
/Users/himanshu/flutter/packages/flutter/lib/src/widgets/actions.dart:361:9: Error: Null safety features are disabled for this library.
Try removing the package language version or setting the language version to 2.10 or higher.
  Object? invoke(covariant T intent) => onInvoke(intent);
        ^
/Users/himanshu/flutter/packages/flutter/lib/src/widgets/actions.dart:386:9: Error: Null safety features are disabled for this library.
Try removing the package language version or setting the language version to 2.10 or higher.
  Object? invokeAction(covariant Action<Intent> action, covariant Intent intent, [BuildContext? context]) {
        ^
/Users/himanshu/flutter/packages/flutter/lib/src/widgets/actions.dart:386:95: Error: Null safety features are disabled for this library.
Try removing the package language version or setting the language version to 2.10 or higher.
  Object? invokeAction(covariant Action<Intent> action, covariant Intent intent, [BuildContext? context]) {
                                                                                              ^
/Users/himanshu/flutter/packages/flutter/lib/src/widgets/actions.dart:420:8: Error: Null safety features are disabled for this library.
Try removing the package language version or setting the language version to 2.10 or higher.
    Key? key,
       ^
/Users/himanshu/flutter/packages/flutter/lib/src/widgets/actions.dart:436:25: Error: Null safety features are disabled for this library.
Try removing the package language version or setting the language version to 2.10 or higher.
  final ActionDispatcher? dispatcher;
                        ^
/Users/himanshu/flutter/packages/flutter/lib/src/widgets/actions.dart:495:22: Error: Null safety features are disabled for this library.
Try removing the package language version or setting the language version to 2.10 or higher.
  static VoidCallback? handler<T extends Intent>(BuildContext context, T intent, {bool nullOk = false}) {
                     ^
/Users/himanshu/flutter/packages/flutter/lib/src/widgets/actions.dart:510:19: Error: Null safety features are disabled for this library.
Try removing the package language version or setting the language version to 2.10 or higher.
  static Action<T>? find<T extends Intent>(BuildContext context, {bool nullOk = false}) {
                  ^
/Users/himanshu/flutter/packages/flutter/lib/src/widgets/actions.dart:595:16: Error: Null safety features are disabled for this library.
Try removing the package language version or setting the language version to 2.10 or higher.
  static Object? invoke<T extends Intent>(
               ^
/Users/himanshu/flutter/packages/flutter/lib/src/widgets/actions.dart:653:22: Error: Null safety features are disabled for this library.
Try removing the package language version or setting the language version to 2.10 or higher.
  Set<Action<Intent>>? listenedActions = <Action<Intent>>{};
                     ^
/Users/himanshu/flutter/packages/flutter/lib/src/widgets/actions.dart:718:8: Error: Null safety features are disabled for this library.
Try removing the package language version or setting the language version to 2.10 or higher.
    Key? key,
       ^
/Users/himanshu/flutter/packages/flutter/lib/src/widgets/actions.dart:719:21: Error: Expected '}' before this.
    required Widget child,
                    ^^^^^
/Users/himanshu/flutter/packages/flutter/lib/src/widgets/actions.dart:724:25: Error: Null safety features are disabled for this library.
Try removing the package language version or setting the language version to 2.10 or higher.
  final ActionDispatcher? dispatcher;
                        ^
/Users/himanshu/flutter/packages/flutter/lib/src/widgets/actions.dart:887:8: Error: Null safety features are disabled for this library.
Try removing the package language version or setting the language version to 2.10 or higher.
    Key? key,
       ^
/Users/himanshu/flutter/packages/flutter/lib/src/widgets/actions.dart:914:18: Error: Null safety features are disabled for this library.
Try removing the package language version or setting the language version to 2.10 or higher.
  final FocusNode? focusNode;
                 ^
/Users/himanshu/flutter/packages/flutter/lib/src/widgets/actions.dart:920:34: Error: Null safety features are disabled for this library.
Try removing the package language version or setting the language version to 2.10 or higher.
  final Map<Type, Action<Intent>>? actions;
                                 ^
/Users/himanshu/flutter/packages/flutter/lib/src/widgets/actions.dart:923:35: Error: Null safety features are disabled for this library.
Try removing the package language version or setting the language version to 2.10 or higher.
  final Map<LogicalKeySet, Intent>? shortcuts;
                                  ^
/Users/himanshu/flutter/packages/flutter/lib/src/widgets/actions.dart:929:27: Error: Null safety features are disabled for this library.
Try removing the package language version or setting the language version to 2.10 or higher.
  final ValueChanged<bool>? onShowFocusHighlight;
                          ^
/Users/himanshu/flutter/packages/flutter/lib/src/widgets/actions.dart:934:27: Error: Null safety features are disabled for this library.
Try removing the package language version or setting the language version to 2.10 or higher.
  final ValueChanged<bool>? onShowHoverHighlight;
                          ^
/Users/himanshu/flutter/packages/flutter/lib/src/widgets/actions.dart:939:27: Error: Null safety features are disabled for this library.
Try removing the package language version or setting the language version to 2.10 or higher.
  final ValueChanged<bool>? onFocusChange;
                          ^
/Users/himanshu/flutter/packages/flutter/lib/src/widgets/actions.dart:1031:41: Error: Null safety features are disabled for this library.
Try removing the package language version or setting the language version to 2.10 or higher.
  void _mayTriggerCallback({VoidCallback? task, FocusableActionDetector? oldWidget}) {
                                        ^
/Users/himanshu/flutter/packages/flutter/lib/src/widgets/actions.dart:1031:72: Error: Null safety features are disabled for this library.
Try removing the package language version or setting the language version to 2.10 or higher.
  void _mayTriggerCallback({VoidCallback? task, FocusableActionDetector? oldWidget}) {
                                                                       ^
/Users/himanshu/flutter/packages/flutter/lib/src/widgets/animated_cross_fade.dart:121:8: Error: Null safety features are disabled for this library.
Try removing the package language version or setting the language version to 2.10 or higher.
    Key? key,
       ^
/Users/himanshu/flutter/packages/flutter/lib/src/widgets/animated_cross_fade.dart:164:17: Error: Null safety features are disabled for this library.
Try removing the package language version or setting the language version to 2.10 or higher.
  final Duration? reverseDuration;
                ^
/Users/himanshu/flutter/packages/flutter/lib/src/widgets/animated_cross_fade.dart:250:22: Error: Null safety features are disabled for this library.
Try removing the package language version or setting the language version to 2.10 or higher.
  AnimationController? _controller;
                     ^
/Users/himanshu/flutter/packages/flutter/lib/src/widgets/animated_cross_fade.dart:251:8: Error: A method declaration needs an explicit list of parameters.
Try adding a parameter list to the method declaration.
  late Animation<double> _firstAnimation;
       ^^^^^^^^^
/Users/himanshu/flutter/packages/flutter/lib/src/widgets/animated_cross_fade.dart:251:26: Error: Expected '{' before this.
  late Animation<double> _firstAnimation;
                         ^^^^^^^^^^^^^^^
/Users/himanshu/flutter/packages/flutter/lib/src/widgets/animated_cross_fade.dart:251:26: Error: Variables must be declared using the keywords 'const', 'final', 'var' or a type name.
Try adding the name of the type of the variable or the keyword 'var'.
  late Animation<double> _firstAnimation;
                         ^^^^^^^^^^^^^^^
/Users/himanshu/flutter/packages/flutter/lib/src/widgets/animated_cross_fade.dart:252:8: Error: A method declaration needs an explicit list of parameters.
Try adding a parameter list to the method declaration.
  late Animation<double> _secondAnimation;
       ^^^^^^^^^
/Users/himanshu/flutter/packages/flutter/lib/src/widgets/animated_cross_fade.dart:252:26: Error: Expected '{' before this.
  late Animation<double> _secondAnimation;
                         ^^^^^^^^^^^^^^^^
/Users/himanshu/flutter/packages/flutter/lib/src/widgets/animated_cross_fade.dart:252:8: Error: 'Animation' is already declared in this scope.
  late Animation<double> _secondAnimation;
       ^^^^^^^^^
/Users/himanshu/flutter/packages/flutter/lib/src/widgets/animated_cross_fade.dart:251:8: Context: Previous declaration of 'Animation'.
  late Animation<double> _firstAnimation;
       ^^^^^^^^^
/Users/himanshu/flutter/packages/flutter/lib/src/widgets/animated_cross_fade.dart:252:26: Error: Variables must be declared using the keywords 'const', 'final', 'var' or a type name.
Try adding the name of the type of the variable or the keyword 'var'.
  late Animation<double> _secondAnimation;
                         ^^^^^^^^^^^^^^^^
/Users/himanshu/flutter/packages/flutter/lib/src/widgets/animated_cross_fade.dart:274:3: Error: 'Animation' isn't a type.
  Animation<double> _initAnimation(Curve curve, bool inverted) {
  ^^^^^^^^^
/Users/himanshu/flutter/packages/flutter/lib/src/widgets/animated_cross_fade.dart:274:3: Context: This isn't a type.
  Animation<double> _initAnimation(Curve curve, bool inverted) {
  ^^^^^^^^^
/Users/himanshu/flutter/packages/flutter/lib/src/widgets/animated_list.dart:33:28: Error: Null safety features are disabled for this library.
Try removing the package language version or setting the language version to 2.10 or higher.
  final AnimationController? controller;
                           ^
/Users/himanshu/flutter/packages/flutter/lib/src/widgets/animated_list.dart:34:39: Error: Null safety features are disabled for this library.
Try removing the package language version or setting the language version to 2.10 or higher.
  final AnimatedListRemovedItemBuilder? removedItemBuilder;
                                      ^
/Users/himanshu/flutter/packages/flutter/lib/src/widgets/animated_list.dart:272:8: Error: Null safety features are disabled for this library.
Try removing the package language version or setting the language version to 2.10 or higher.
    Key? key,
       ^
/Users/himanshu/flutter/packages/flutter/lib/src/widgets/animated_list.dart:340:25: Error: Null safety features are disabled for this library.
Try removing the package language version or setting the language version to 2.10 or higher.
  final ScrollController? controller;
                        ^
/Users/himanshu/flutter/packages/flutter/lib/src/widgets/animated_list.dart:350:13: Error: Null safety features are disabled for this library.
Try removing the package language version or setting the language version to 2.10 or higher.
  final bool? primary;
            ^
/Users/himanshu/flutter/packages/flutter/lib/src/widgets/animated_list.dart:358:22: Error: Null safety features are disabled for this library.
Try removing the package language version or setting the language version to 2.10 or higher.
  final ScrollPhysics? physics;
                     ^
/Users/himanshu/flutter/packages/flutter/lib/src/widgets/animated_list.dart:377:27: Error: Null safety features are disabled for this library.
Try removing the package language version or setting the language version to 2.10 or higher.
  final EdgeInsetsGeometry? padding;
                          ^
/Users/himanshu/flutter/packages/flutter/lib/src/widgets/animated_list.dart:388:27: Error: Null safety features are disabled for this library.
Try removing the package language version or setting the language version to 2.10 or higher.
  static AnimatedListState? of(BuildContext context, { bool nullOk = false }) {
                          ^
/Users/himanshu/flutter/packages/flutter/lib/src/widgets/animated_list.dart:737:8: Error: Null safety features are disabled for this library.
Try removing the package language version or setting the language version to 2.10 or higher.
    Key? key,
       ^
/Users/himanshu/flutter/packages/flutter/lib/src/widgets/animated_list.dart:774:33: Error: Null safety features are disabled for this library.
Try removing the package language version or setting the language version to 2.10 or higher.
  static SliverAnimatedListState? of(BuildContext context, {bool nullOk = false}) {
                                ^
/Users/himanshu/flutter/packages/flutter/lib/src/widgets/animated_list.dart:837:14: Error: Null safety features are disabled for this library.
Try removing the package language version or setting the language version to 2.10 or higher.
  _ActiveItem? _removeActiveItemAt(List<_ActiveItem> items, int itemIndex) {
             ^
/Users/himanshu/flutter/packages/flutter/lib/src/widgets/animated_list.dart:842:14: Error: Null safety features are disabled for this library.
Try removing the package language version or setting the language version to 2.10 or higher.
  _ActiveItem? _activeItemAt(List<_ActiveItem> items, int itemIndex) {
             ^
/Users/himanshu/flutter/packages/flutter/lib/src/widgets/animated_size.dart:57:8: Error: Null safety features are disabled for this library.
Try removing the package language version or setting the language version to 2.10 or higher.
    Key? key,
       ^
/Users/himanshu/flutter/packages/flutter/lib/src/widgets/animated_size.dart:58:11: Error: Null safety features are disabled for this library.
Try removing the package language v

Rei*_*tor 14

我通过执行以下操作解决了它(对于 Windows 10 上的 Visual Code):

在命令提示符(或在 PATH 中使用 flutter 的任何终端):

flutter upgrade

并确保版本至少为 2.12(这是在不将其用作实验性功能的情况下启用空安全所需的最低版本(我相信))

PS C:\> flutter upgrade
Flutter is already up to date on channel stable
Flutter 2.0.2 • channel stable • https://github.com/flutter/flutter.git 
Framework • revision 8962f6dc68 (2 days ago) • 2021-03-11 13:22:20 -0800
Engine • revision 5d8bf811b3
Tools • Dart 2.12.1
Run Code Online (Sandbox Code Playgroud)

当被证实的话,我查了一下我目前的SDK版本中的项目是(在我的情况下,它是以下情况:sdk: ">=2.7.0 <3.0.0"

所以,我更新了它是不是以下内容:sdk: ">=2.12.0 <3.0.0"

所以环境应该如下所示:

PS C:\> flutter upgrade
Flutter is already up to date on channel stable
Flutter 2.0.2 • channel stable • https://github.com/flutter/flutter.git 
Framework • revision 8962f6dc68 (2 days ago) • 2021-03-11 13:22:20 -0800
Engine • revision 5d8bf811b3
Tools • Dart 2.12.1
Run Code Online (Sandbox Code Playgroud)


GJJ*_*GJJ 4

切换到开发/主通道

尝试在文件中添加sdk(支持空安全)pubspec.yaml。就我而言

environment:
  sdk: ">=2.12.0-27.0.dev <2.12.0"
Run Code Online (Sandbox Code Playgroud)

创建analysis_options.yaml和添加

analyzer:
  enable-experiment:
    - non-nullable
Run Code Online (Sandbox Code Playgroud)

[选修的]

如果你使用 vs code 尝试添加

{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
    {
        "name": "name",
        "request": "launch",
        "type": "dart",
        "vmAdditionalArgs": [
            "--enable-experiment=non-nullable",
        ],
    }
]
}
Run Code Online (Sandbox Code Playgroud)