简体   繁体   English

库“package:flutter/material.dart”是遗留的,不应导入到 null 安全库中

[英]The library 'package:flutter/material.dart' is legacy, and should not be imported into a null safe library

I have a null-safe library and in the example folder I'm using the following import:我有一个 null-safe 库,在示例文件夹中我使用了以下导入:

import 'package:flutter/material.dart';

However, the linter is giving me the following warning:但是,linter 给我以下警告:

The library 'package:flutter/material.dart' is legacy, and should not be imported into a null safe library.库“package:flutter/material.dart”是遗留的,不应导入到 null 安全库中。 Try migrating the imported library.尝试迁移导入的库。 import_of_legacy_library_into_null_safe import_of_legacy_library_into_null_safe

The example project's pubspec.yaml file specifies the beta version of the Dart SDK:示例项目的 pubspec.yaml 文件指定了 Dart SDK 的 beta 版本:

environment:
  sdk: ">=2.12.0-29.10.beta <3.0.0"

dependencies:
  flutter:
    sdk: flutter
  my_library:
    path: ../

Hasn't material.dart already been converted by now? material.dart这时候不是已经转换了吗? Do I need to add something else to pubspec.yaml or just wait for the stable release to come out?我需要向 pubspec.yaml 添加其他内容还是等待稳定版本发布?

Use dart pub outdated --mode=null-safety and then dart pub upgrade --null-safety to upgrade all your dependencies to null-safety.使用dart pub outdated --mode=null-safety然后dart pub upgrade --null-safety将所有依赖项升级到 null-safety。

For more details go to https://dart.dev/null-safety/migration-guide .有关详细信息 go 至https://dart.dev/null-safety/migration-guide

The fix for this is relatively simple.对此的修复相对简单。 Just go to your pubspec.yaml file and make sure the lottie dependancy that you have there, is the latest version as on the pub.dev site.只需将 go 复制到您的 pubspec.yaml 文件,并确保您在那里的乐天依赖关系是 pub.dev 站点上的最新版本。

Currently, on 8/29/2021, a uto_size_text package also keeps giving this alert , because I was using the Null Safety versions of Dart - 2.12.0, and to solve this, I looked in the package documentation and saw that I had a Prerelease version to Null Safety - launch, so I used it.目前,在 2021 年 8 月 29 日, uto_size_text package 也一直发出此警报,因为我使用的是 Null 安全版本 Dart - 2.12.0,为了解决这个问题,我查看了 package 文档,发现我有一个Prerelease version to Null Safety - launch,所以用了。

dependencies:
  auto_size_text: ^3.0.0-nullsafety.0

[:[The library 'package:flutter_ / .dart' is legacy, and should not be imported into a null safe library. [:[库 'package:flutter_ / .dart' 是遗留的,不应导入到 null 安全库中。 Try migrating the imported library.尝试迁移导入的库。

Open run/debug option -> select edit configuration as shown in image one.] 1 ] 1打开运行/调试选项 -> select 编辑配置,如图一所示。] 1 ] 1

然后在 Additional run args 部分添加 --no-sound-null-safety -> Apply->ok->run appllication 它对我有用 .imgur.com/A9aEb.png .imgur.com/A9aEb.png

I was facing the same problem with the Adhan Dart package, when i read the documentation on the package site, i had the Prereleased version so i made changes to the dependences as adhan: ^2.0.0-nullsafety.2 and it worked.我在Adhan Dart package 上遇到了同样的问题,当我阅读 package 网站上的文档时,我有预发布版本,所以我将依赖项更改为adhan: ^2.0.0-nullsafety.2并且它有效。

For more details: https://pub.dev/packages/adhan/versions/2.0.0-nullsafety.1更多详情: https://pub.dev/packages/adhan/versions/2.0.0-nullsafety.1

In case someone comes here looking for this error because of the flutter realm package. Please change your realm version in your pubspec.yaml file to a version with null safety.如果有人因为 flutter realm package 来这里寻找这个错误。请将pubspec.yaml文件中的 realm 版本更改为具有 null 安全性的版本。 Check out the latest realm versions from https://pub.dev/packages/realm/versions .https://pub.dev/packages/realm/versions查看最新的 realm 版本。

Change From更改自

dependencies
  realm: ^0.0.1

To

dependencies
   realm: ^0.8.0+rc  //check for latest version

go to https://pub.dev/packages/font_awesome_flutter , go 到https://pub.dev/packages/font_awesome_flutter ,

copy the latest release version of font ie in my case (font_awesome_flutter: ^9.1.0),在我的例子中复制最新版本的字体 ie (font_awesome_flutter: ^9.1.0),

then add it to your pubspec.yaml file ie (font_awesome_flutter: ^9.1.0),然后将其添加到您的 pubspec.yaml 文件中,即 (font_awesome_flutter: ^9.1.0),

click pub get dependencies单击 pub 获取依赖项

go to your input_page file go 到您的 input_page 文件

click get dependencies单击获取依赖项

Copy the latest version of the package which is giving the error from http://pub.dev/ and paste it in the pubspec.yaml file.http://pub.dev/复制最新版本的 package,并将其粘贴到 pubspec.yaml 文件中。

In my case I got this error because I defined 'firebase_core' dependency in the pubspec.yaml file under the 'dev_dependencies' but it was wrong.就我而言,我收到此错误是因为我在 pubspec.yaml 文件中的“dev_dependencies”下定义了“firebase_core”依赖项,但这是错误的。

I've done 3 easy steps to solve the issue as following:我已经完成了 3 个简单的步骤来解决问题,如下所示:

1- I've got the latest version from https://pub.dev/packages website. 1- 我从https://pub.dev/packages网站获得了最新版本。

2- I've defined the packages under 'dependencies' in the pubspec.yaml file as following: 2- 我在 pubspec.yaml 文件中的“依赖项”下定义了如下包:

dependencies:
  flutter:
    sdk: flutter
  firebase_core: ^2.3.0

3- I've imported the package in the main.dart file as following: 3- 我在 main.dart 文件中导入了 package,如下所示:

import 'package:firebase_core/firebase_core.dart';

Future main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await Firebase.initializeApp();
  runApp(MyApp());
}

in my case my firebase_core package was not of the latest version.在我的例子中,我的 firebase_core package 不是最新版本。 do check yours or any other firebase related dependencies.请检查您的或任何其他 firebase 相关的依赖项。 some packages maybe old version.一些软件包可能是旧版本。

If you want to use null safety, either wait for the stable release so that all of the dependencies can support the null safety.如果要使用 null 安全性,要么等待稳定版本,以便所有依赖项都可以支持 null 安全性。
Or you can use the null safety by switching to the beta channel of the Flutter SDK.或者,您可以通过切换到 Flutter SDK 的 beta 通道来使用 null 安全性。

Use the following command to switch to the flutter beta channel.使用以下命令切换到 flutter beta 通道。

$ flutter channel beta
$ flutter upgrade

Be careful if you are working on production code because this may break something in the code.如果您正在处理生产代码,请小心,因为这可能会破坏代码中的某些内容。 If you are working on production then stick to the flutter stable channel.如果您正在进行生产,请坚持使用 flutter 稳定通道。

You can check the dependency status using the following command:您可以使用以下命令检查依赖关系状态:

$ dart pub outdated --mode=null-safety

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 库“package:vin_decoder/vin_decoder.dart”是遗留的,不应导入到 null 安全库中 - The library 'package:vin_decoder/vin_decoder.dart' is legacy, and should not be imported into a null safe library URI 的目标不存在:'package:flutter/material.dart' - Target of URI doesn't exist: 'package:flutter/material.dart' url 的目标不存在 'package:flutter/material.dart' - Target of url doesn't exist 'package:flutter/material.dart' URI 的目标不存在 'package:flutter/material.dart' - Target of URI doesn't exist 'package:flutter/material.dart' Visual Studio Code - URI 的目标不存在 'package:flutter/material.dart' - Visual Studio Code - Target of URI doesn't exist 'package:flutter/material.dart' 添加 'value:' 参数时出现 DropdownButton 异常。 “package:flutter/material.dart/dropdown.dart 断言失败” - DropdownButton excepcion when adding the 'value:' parameter. “package:flutter/material.dart/dropdown.dart Failed assertion ” flutter material.dart 和 pubspec.yaml 文件错误 - flutter material.dart and pubspec.yaml file error 错误:URI 的目标不存在:'package:flutter/material.dart'。 (uri_does_not_exist at [myapp] test/widget_test.dart:8) - Error: Target of URI doesn't exist: 'package:flutter/material.dart'. (uri_does_not_exist at [myapp] test/widget_test.dart:8) ClojureDart:主机编译时出错(ns samples.tables(:require [“package:flutter/material.dart”:as m] [cljd.flutter.alpha as f])) - ClojureDart: Error while host-compiling (ns samples.tables (:require ["package:flutter/material.dart" :as m] [cljd.flutter.alpha as f])) 如何在flutter新建无状态或有状态class时自动添加material.dart - How to automatically add material.dart when creating new stateless or stateful class in flutter
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM