尝试运行命令“flutter run”时出错

Posted

技术标签:

【中文标题】尝试运行命令“flutter run”时出错【英文标题】:Error when trying to run command 'flutter run' 【发布时间】:2021-08-29 01:21:30 【问题描述】:

我试图运行命令“flutter run”它给了我错误。颤振医生没有问题。不知道哪里出错了,我尝试运行这个flutter clean,flutter pub cache repair,flutter run。还是一样的错误。

Warning: You are using these overridden dependencies:                   
! intl 0.17.0
Running "flutter pub get" in cretello_rentors_plus_1...            34.3s
Using hardware rendering with device sdk gphone x86 arm. If you notice graphics
artifacts, consider enabling software rendering with
"--enable-software-rendering".
Launching lib\main.dart on sdk gphone x86 arm in debug mode...
/C:/src/flutterSDK/flutter/.pub-cache/hosted/pub.dartlang.org/dynamic_theme-1.0.1/lib/dynamic_theme.dart:25:46: Error: Method not found: 'TypeMatcher'.
    return context.ancestorStateOfType(const TypeMatcher<DynamicThemeState>());
                                             ^^^^^^^^^^^
/C:/src/flutterSDK/flutter/.pub-cache/hosted/pub.dartlang.org/dynamic_theme-1.0.1/lib/dynamic_theme.dart:25:20: Error: The method 'ancestorStateOfType' isn't defined for the class 'BuildContext'.
 - 'BuildContext' is from 'package:flutter/src/widgets/framework.dart' ('/C:/src/flutterSDK/flutter/packages/flutter/lib/src/widgets/framework.dart').
Try correcting the name to the name of an existing method, or defining a method named 'ancestorStateOfType'.
    return context.ancestorStateOfType(const TypeMatcher<DynamicThemeState>());  
                   ^^^^^^^^^^^^^^^^^^^
                                                                        
                                                                        
FAILURE: Build failed with an exception.

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

* What went wrong:
Execution failed for task ':app:compileFlutterBuildDebug'.
> Process 'command 'C:\src\flutterSDK\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 43s
Running Gradle task 'assembleDebug'...                                  
Running Gradle task 'assembleDebug'... Done                        44.8s
Exception: Gradle task assembleDebug failed with exit code 1```

【问题讨论】:

【参考方案1】:

尝试其中一种解决方案 ——— https://github.com/fluttercommunity/flutter_google_places/issues/140

【讨论】:

【参考方案2】:

此问题是由于您的颤振版本造成的。如果要复制其他代码,请务必先运行。

flutter cleanflutter pub get

如果这不起作用,请确保您使用正确版本的颤振 sdk。

【讨论】:

以上是关于尝试运行命令“flutter run”时出错的主要内容,如果未能解决你的问题,请参考以下文章

Flutter Run 不工作,在 iPhone 上启动应用程序时出错

为啥 Flutter 应用程序不能使用命令 flutter run -d chrome 在 chrome 上运行

无法运行颤振命令

当我运行 flutter run 时,Flutter iOS 构建失败

如何在目标设备作为 android 的情况下“flutter run”?

尝试运行 npm start 命令时出错