如何解决错误:未为 flutter 中的类“TextTheme”定义 getter“body1”?

Shr*_*rma 7 dart flutter flutter-dependencies

我的 flutter 应用程序无法在2.5.0-5.3.prebeta 版本上运行。之后我搜索了它,然后需要升级我的 flutter sdk,因此已升级到最新的 beta 版本 2.6.0-5.2.pre,但仍然出现错误。\nplace_picker-0.9.19-nullsafety插件的错误。并且无法解决它。

\n

错误日志:

\n
../../../../Workspace/flutter/.pub-cache/hosted/pub.dartlang.org/place_picker-0.9.19-nullsafety/lib/widgets/rich_suggestion.dart:35:89: Error: The getter \'body1\' isn\'t defined for the class \'TextTheme\'.\n - \'TextTheme\' is from \'package:flutter/src/material/text_theme.dart\' (\'../../../../Workspace/flutter/packages/flutter/lib/src/material/text_theme.dart\').\nTry correcting the name to the name of an existing getter, or defining a getter or field named \'body1\'.\n      TextSpan(text: boldText, style: style.copyWith(color: Theme.of(context).textTheme.body1!.color)),\n                                                                                        ^^^^^\n../../../../Workspace/flutter/.pub-cache/hosted/pub.dartlang.org/place_picker-0.9.19-nullsafety/lib/widgets/search_input.dart:60:65: Error: The getter \'body1\' isn\'t defined for the class \'TextTheme\'.\n - \'TextTheme\' is from \'package:flutter/src/material/text_theme.dart\' (\'../../../../Workspace/flutter/packages/flutter/lib/src/material/text_theme.dart\').\nTry correcting the name to the name of an existing getter, or defining a getter or field named \'body1\'.\n          Icon(Icons.search, color: Theme.of(context).textTheme.body1!.color),\n                                                                ^^^^^\n\n\nFAILURE: Build failed with an exception.\n\n* Where:\nScript \'/Users/brightroots/Workspace/flutter/packages/flutter_tools/gradle/flutter.gradle\' line: 1005\n\n* What went wrong:\nExecution failed for task \':app:compileFlutterBuildDebug\'.\n> Process \'command \'/Users/brightroots/Workspace/flutter/bin/flutter\'\' finished with non-zero exit value 1\n\n* Try:\nRun 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.\n\n* Get more help at https://help.gradle.org\n\nBUILD FAILED in 31s\n\n
Run Code Online (Sandbox Code Playgroud)\n

错误:

\n

在此输入图像描述

\n

我当前的 FUTTER 版本:

\n
Flutter 2.6.0-5.2.pre \xe2\x80\xa2 channel beta \xe2\x80\xa2 https://github.com/flutter/flutter.git\nFramework \xe2\x80\xa2 revision 400608f101 (8 days ago) \xe2\x80\xa2 2021-09-15 15:50:26 -0700\nEngine \xe2\x80\xa2 revision 1d521d89d8\nTools \xe2\x80\xa2 Dart 2.15.0 (build 2.15.0-82.2.beta)\n
Run Code Online (Sandbox Code Playgroud)\n

Alb*_*nar 5

我正在处理这个错误。就我而言,这是因为存在与 flutter 2.5 不兼容的依赖项。我尝试了很多解决方案。但只有这个对我有用。

首先将其添加到您的 pubspec.yaml 中

 charts_flutter:
    git:
      url: git://github.com/google/charts.git
      path: charts_flutter
Run Code Online (Sandbox Code Playgroud)

如此链接所述 。

如果您有错误提示:remote end hung up unexpectedly while git cloning,

然后运行这个命令

git config --global http.postBuffer 500M
git config --global http.maxRequestBuffer 100M
git config --global core.compression 0 
Run Code Online (Sandbox Code Playgroud)

正如这个答案所描述的

这解决了我的问题。

  • 虽然此链接可以回答问题,但最好在此处包含答案的基本部分并提供链接以供参考。如果链接页面发生更改,仅链接的答案可能会变得无效。- [来自评论](/review/late-answers/30222535) (2认同)

Oma*_*att 0

日志上抛出的错误似乎是由您正在使用的插件抛出的:place_picker-0.9.19-nullsafety。日志表明问题来自Theme.of(context).textTheme.body1

检查 Flutter 文档,TextTheme上的 body1定义为bodyText1. 您可能需要考虑更新 TextTheme 中调用 body1 的方式。否则,您可以跟踪在 GitHub 上提交的与此问题相关的问题票证。