如何解决"Execution failed for task ':app:compileFlutterBuildDebug'."



当我尝试在android上运行应用程序"flutter run"在终端中,我得到以下错误…

/C:/Users/Acer/AppData/Roaming/Pub/Cache/hosted/pub.dartlang.org/provider-3.2.0/lib/src/delegate_widget.dart:194:18: Error: Superclass has no method named 'inheritFromElement'.
return super.inheritFromElement(ancestor, aspect: aspect);
^^^^^^^^^^^^^^^^^^
/C:/Users/Acer/AppData/Roaming/Pub/Cache/hosted/pub.dartlang.org/provider-3.2.0/lib/src/provider.dart:259:19: Error: The method 'inheritFromWidgetOfExactType' isn't defined for the class 'BuildContext'.
- 'BuildContext' is from 'package:flutter/src/widgets/framework.dart' ('/D:/Flutter/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 InheritedProvider<T>
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
/C:/Users/Acer/AppData/Roaming/Pub/Cache/hosted/pub.dartlang.org/provider-3.2.0/lib/src/provider.dart:260:19: Error: The method 'ancestorInheritedElementForWidgetOfExactType' isn't defined for the class 'BuildContext'.
- 'BuildContext' is from 'package:flutter/src/widgets/framework.dart' ('/D:/Flutter/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
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
/C:/Users/Acer/AppData/Roaming/Pub/Cache/hosted/pub.dartlang.org/flutter_svg-0.18.1/lib/src/picture_provider.dart:50:59: Error: No named parameter with 
the name 'nullOk'.
context != null ? Localizations.localeOf(context, nullOk: true) : null,
^^^^^^
/D:/Flutter/flutter/packages/flutter/lib/src/widgets/localizations.dart:413:17: Context: Found this candidate, but the arguments don't match.
static Locale localeOf(BuildContext context) {
^^^^^^^^
  
FAILURE: Build failed with an exception.
* Where:
Script 'D:Flutterflutterpackagesflutter_toolsgradleflutter.gradle' line: 991
* What went wrong:
Execution failed for task ':app:compileFlutterBuildDebug'.
> Process 'command 'D:Flutterflutterbinflutter.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 1m 50s
Running Gradle task 'assembleDebug'...
Running Gradle task 'assembleDebug'... Done                       121.0s
Exception: Gradle task assembleDebug failed with exit code 1

事情是昨天它工作正常,但今天它显示这个错误消息。请帮忙解决。

更新提供商版本4.3.3,它将解决这个问题

编辑-与flutter 2 out,它将无法工作。答案现在已经过时了

切换到主频道时出现此问题。不得不降级

flutter channel stable && flutter upgrade

修复了

我有同样的问题在过去的3天。如果你不想使用降级的颤振版本,我还有一个解决方案:首先,如果您使用

将其降级,请更新您的flutter版本:
flutter upgrade

在调试控制台中,您可以注意到您正在使用提供者 版本3.2.0

错误输出中的。我认为如果你使用的provider的版本大于

版本4.0.0

provider: ^3.2.0替换为provider: ^4.0.0

(您可以在pubspec中调整它。yaml文件)

就可以了

试一试,让我知道这是否解决了问题:)

将provider: ^3.2.0替换为provider: ^4.0.0这对我很有效(您可以在pubspec中对此进行调整。yaml文件)

您可能在一个通道中升级了颤振而不是'稳定'。在这种情况下,最简单的解决方案是打开终端并运行(键入)flutter downgrade.

请将依赖项升级到最新版本。我自己找到解决办法。发生此错误是由于复制完整的代码,这是在旧版本上完成的,现在最新版本启用了null安全,所以这就是问题的原因。

更新提供商版本4.3.3,它将解决这个问题

,如果它给你一个null安全错误,在android studio的run选项卡中编辑你的配置在附加的运行参数中添加:-

——no-sound-null-safety

,点击应用。

这肯定会清除你的错误

尝试将提供程序版本更新到4.0.0或更高版本。我有同样的问题,更新提供程序版本解决了我的问题

FOR ME

将提供程序版本从3.0.0更新到4.3.3工作,同时将参数名称从builder更改为create

最新更新