我无法调试 Flutter 项目
这是错误
/C:/src/flutter/.pub-cache/hosted/pub.dartlang.org/country_pickers-1.3.0/lib/utils/my_alert_dialog.dart:139:36: Error: Method not found: 'ButtonTheme.bar'.
children.add(new ButtonTheme.bar(
^^^
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
BUILD FAILED in 18s
Exception: Gradle task assembleDebug failed with exit code 1
答案 0 :(得分:0)
错误:
/C:/src/flutter/.pub-cache/hosted/pub.dartlang.org/country_pickers-1.3.0/lib/utils/my_alert_dialog.dart:139:36: Error: Method not found: 'ButtonTheme.bar'.
children.add(new ButtonTheme.bar(
告诉您 Error: Method not found: 'ButtonTheme.bar'
出现在包 country_pickers-1.3.0
中。仅搜索错误消息会发现 Error: Method not found: 'ButtonTheme.bar',它告诉您 ButtonTheme.bar
已被弃用,现在显然不再受支持。
转到 country_pickers
包页面并找到 Changelog 并搜索我们看到的 ButtonTheme.bar
:
[2.0.0] - 03/13/2021
Null-safety is added
Fix issue #40 (Country Code Not available for "Lao People's Democratic Republic") by @Tan-JamickoJohn
Fix issue #53 and #59 (Deprecated ButtonTheme.bar is removed) by @phamnhuvu-dev
Fix issue #45 (Search doesn't show all results) by @shadyshrif
Thanks @phamnhuvu-dev, @shadyshrif, @Tan-JamickoJohn
因此软件包所有者在版本 2.0.0
中修复了该问题。
所以你要么 a) 停止使用这个包,b) 升级到新的包版本,或者 c) 使用仍然支持 ButtoneTheme.bar
的 Flutter 版本。 b) 的问题在于新版本支持空安全,这将要求您自己采用空安全 - 请参阅此 link。 c) 的问题是您将绑定到旧版本的 Flutter,这不是一个好主意。
答案 1 :(得分:-1)
这是非常常见的错误,很容易修复。
如果您没有 Git,请不要担心。
flutter clean
命令,然后刷新 pubspec.yaml
flutter upgrade
它。