颤振构建问题

时间:2021-03-31 17:25:34

标签: android flutter

当我尝试在测试设备上打开使用 Flutter 制作的应用程序时,出现以下错误。我尝试了很多方法,但无法获得成功的结果。您认为错误是什么,我该如何解决?

/C:/src/flutter/.pub-cache/hosted/pub.dartlang.org/provider-2.0.1+1/lib/src/provider.dart:179:19: Error: The method 'inheritFromWidgetOfExactType' isn't defined for the class 'BuildContext'.
 - 'BuildContext' is from 'package:flutter/src/widgets/framework.dart' ('/C:/src/flutter/packages/flutter/lib/src/widgets/framework.dart').
Try correcting the name to the name of an existing method, or defining a method named 'inheritFromWidgetOfExactType'.
        ? context.inheritFromWidgetOfExactType(type) as _Provider<T>
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
/C:/src/flutter/.pub-cache/hosted/pub.dartlang.org/provider-2.0.1+1/lib/src/provider.dart:180:19: Error: The method 'ancestorInheritedElementForWidgetOfExactType' isn't defined for the class 'BuildContext'.
 - 'BuildContext' is from 'package:flutter/src/widgets/framework.dart' ('/C:/src/flutter/packages/flutter/lib/src/widgets/framework.dart').
Try correcting the name to the name of an existing method, or defining a method named 'ancestorInheritedElementForWidgetOfExactType'.
        : context.ancestorInheritedElementForWidgetOfExactType(type)?.widget
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^


FAILURE: Build failed with an exception.

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

* What went wrong:
Execution failed for task ':app:compileFlutterBuildDebug'.
> Process 'command 'C:\src\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

BU�LD FAILED in 2m 0s
Exception: Gradle task assembleDebug failed with exit code 1

2 个答案:

答案 0 :(得分:0)

您使用的似乎是提供程序库的 2.0.1 版。

此版本与 Flutter 的最新版本不兼容,因为 inheritFromWidgetOfExactType 在 Flutter 1.12 中已弃用

您在这里有两个选择,要么将您使用的 Flutter 版本降级到 1.12 以下,要么将您的 Provider 导入升级到更新的版本(我强烈建议您选择第二个选项!)< /p>

答案 1 :(得分:0)

你应该试试这个。

昨天我刚刚重新启动了我的电脑并遇到了这个问题。我试图寻找这个问题的解决方案,但在我的情况下没有任何效果。

解决方案

只需删除您的 flutter 文件夹(Flutter Source),然后重新安装即可。您的问题将得到解决。