错误:未找到成员:'packageRoot',如何解决Flutter中的ignore:deprecated_member_use?

S. *_*sif 132 android ios dart flutter

在我的flutter项目中,我对插件进行了一些更新,然后使用flutter升级。之后,每当我运行我的 flutter 项目时,它都会显示以下错误-

    /C:/src/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/platform-3.0.2/lib/src/interface/local_platform.dart:46:19: Error: Member not found: 'packageRoot'.
          io.Platform.packageRoot; // ignore: deprecated_member_use
                      ^^^^^^^^^^^ FAILURE: Build failed with an exception.

* Where: Script 'C:\src\flutter\flutter\packages\flutter_tools\gradle\flutter.gradle' line: 1102

* What went wrong: Execution failed for task ':app:compileFlutterBuildDebug'.
> Process 'command 'C:\src\flutter\flutter\bin\flutter.bat'' finished with non-zero exit value 1

* Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 20s Exception: Gradle task assembleDebug failed with exit code 1
Run Code Online (Sandbox Code Playgroud)

所以,我需要一个建议,如何解决这个问题?

Cop*_*oad 193

您需要升级依赖项才能解决此问题,因此运行:

flutter pub upgrade
Run Code Online (Sandbox Code Playgroud)

如果这仍然不起作用,则意味着您因传递依赖而遇到此问题platformplatform版本低于3.1.0此问题)。因此,请像这样覆盖文件platform中的包:pubspec.yaml

dependency_overrides:
  platform: ^3.1.0
Run Code Online (Sandbox Code Playgroud)

  • 我刚刚看到 `path_provider` [传递依赖](https://github.com/flutter/plugins/blob/master/packages/path_provider/path_provider_platform_interface/pubspec.yaml) 也在使用 `platform: 3.0.0`,不幸的是,最新更新的 `path_provider: 2.0.8` 并没有解决这个问题,所以你需要重写我在第二部分中提到的依赖项。 (2认同)

小智 52

尝试添加到 pubspec.yaml 文件中

dependencies: // under dependencies:
  platform: ^3.1.0
Run Code Online (Sandbox Code Playgroud)

然后运行 flutter pub get

为什么会出现这个错误

../../../development/flutter/.pub-cache/hosted/pub.dartlang.org/platform-3.0.0/lib/src/interface/local_platform.dart:46:19: Error: Member not found: 'packageRoot'. io.Platform.packageRoot; // ignore: deprecated_member_use

这是构建文件时会遇到的错误。

如果您发现错误是由包引起的 platform:3.0.0

所以我们只是通过将其增加到来覆盖它3.1.0


Ale*_*lex 34

唯一可以帮助我的是pubspec.lock从项目文件夹中删除该文件,然后运行

flutter clean

flutter pub get
Run Code Online (Sandbox Code Playgroud)

  • 同样在这里。在删除“pubspeck.lock”之前,我永远无法使其正常工作。很好的洞察力,谢谢。 (8认同)

Lin*_*nar 21

flutter pub upgrade

flutter clean

flutter pub get
Run Code Online (Sandbox Code Playgroud)

  • 我的 flutter 版本 2.10.1 对我不起作用 (3认同)

om-*_*-ha 10

解决方案

A.删除pubspec.lock

  • 删除pubspec.lock文件
  • 为了采取更好的措施,请将platform的父 pub 例如更新path_provider到最新版本。
  • flutter pub get

B. pubspec 依赖覆盖

  • 添加platform其最新版本作为依赖项覆盖
dependency_overrides:
  # fix `packageRoot`compile error for iOS, because `path_provider` is using an old version of `platform`
  platform: ^3.1.0 # overrides `path_provider`
Run Code Online (Sandbox Code Playgroud)
  • flutter pub get

根本原因

  • platform酒吧已经过时了。在你的情况下,它很可能是来自 pub 的传递依赖path_provider
  • 由于某种原因,flutter pub get不会更新platform这是一个传递依赖项。即使你将其父pub的版本更改path_provider为最新版本并flutter pub get再次调用。

检查platformpub 版本

A.flutter pub deps打印包依赖关系图。然后在输出中找到“ -platform ”字符串。

B. 在pubspec.lock文件内,查找“ platform: ”字符串。

  • `flutter pub get 不会更新平台,这是一个传递依赖。`谢谢您!我试图弄清楚为什么需要它! (2认同)

Ark*_*kay 8

对我来说,清洁和领取包裹是行不通的。这个错误是在我升级flutter之后开始的。我当时在主频道上,对我来说,一个快速解决办法就是切换到稳定频道。

flutter channel stable
flutter upgrade
Run Code Online (Sandbox Code Playgroud)

也许有更好的解决方案直接处理平台包。


Ahm*_*san 8

首先,运行

flutter pub outdated

然后

flutter pub upgrade --major-versions


Tal*_*ick 7

我遇到了同样的问题,并通过以下步骤解决了它:

  1. 跑步flutter pub upgrade
  2. 跑步flutter pub outdated
  3. 跑步flutter pub clean

注意flutter pub clean:在项目根目录和示例包中运行。

另一件重要的事情是确保您使用的是 Flutter 的稳定版本。