如何解决错误:getter 'body1'没有为flutter中的类'TextTheme'定义?

ukdjmx9f  于 2022-12-14  发布在  Flutter
关注(0)|答案(5)|浏览(847)

我的flutter应用程序是不能运行在2.5.0-5.3.pre测试版。之后,我搜索它,然后需要升级我的flutter sdk,所以已经升级到最新的测试版2.6.0-5.2.pre,但仍然得到错误。与place_picker-0.9.19-nullsafety插件的错误。并无法解决它。

错误日志:

../../../../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'.
 - 'TextTheme' is from 'package:flutter/src/material/text_theme.dart' ('../../../../Workspace/flutter/packages/flutter/lib/src/material/text_theme.dart').
Try correcting the name to the name of an existing getter, or defining a getter or field named 'body1'.
      TextSpan(text: boldText, style: style.copyWith(color: Theme.of(context).textTheme.body1!.color)),
                                                                                        ^^^^^
../../../../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'.
 - 'TextTheme' is from 'package:flutter/src/material/text_theme.dart' ('../../../../Workspace/flutter/packages/flutter/lib/src/material/text_theme.dart').
Try correcting the name to the name of an existing getter, or defining a getter or field named 'body1'.
          Icon(Icons.search, color: Theme.of(context).textTheme.body1!.color),
                                                                ^^^^^

FAILURE: Build failed with an exception.

* Where:
Script '/Users/brightroots/Workspace/flutter/packages/flutter_tools/gradle/flutter.gradle' line: 1005

* What went wrong:
Execution failed for task ':app:compileFlutterBuildDebug'.
> Process 'command '/Users/brightroots/Workspace/flutter/bin/flutter'' 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 31s

错误:

我目前的未来版本:

Flutter 2.6.0-5.2.pre • channel beta • https://github.com/flutter/flutter.git
Framework • revision 400608f101 (8 days ago) • 2021-09-15 15:50:26 -0700
Engine • revision 1d521d89d8
Tools • Dart 2.15.0 (build 2.15.0-82.2.beta)
w3nuxt5m

w3nuxt5m1#

我正在处理这个错误。在我的情况下,这是因为有一个依赖关系,不兼容flutter 2.5。我尝试了许多解决方案。但只有这对我有效。
首先将其添加到您的pubspec.yaml

charts_flutter:
    git:
      url: git://github.com/google/charts.git
      path: charts_flutter

如本链接所述。
如果出现以下错误: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

as described on this answer
这解决了我的问题。

8nuwlpux

8nuwlpux2#

将它们添加到依赖项中并从bodyText1中删除body1

charts_flutter:
    git:
      url: git://github.com/google/charts.git
      path: charts_flutter
h5qlskok

h5qlskok3#

日志中的错误似乎是由您使用的插件引发的:place_picker-0.9.19-nullsafety。日志表明问题来自Theme.of(context).textTheme.body1
检查Flutter文档,TextTheme上的body1定义为bodyText1。您可能需要考虑更新TextTheme中调用body1的方式。否则,您可以在GitHub上跟踪与此问题相关的issue ticket文件。

uujelgoq

uujelgoq4#

像下面这样编辑dart包中的行,它就会工作。当然作者应该这样做,但你也可以自己编辑:)

丰富建议.dart

原文:粗体文本,样式:样式.copyWith(颜色:主题.of(上下文).文本主题.body 1!.color)),
新增:文本跨度(文本:粗体文本,样式:样式.copyWith(颜色:主题.of(上下文).文本主题.正文文本1!.颜色)),

搜索输入.dart

图标(图标. search,颜色:主题.of(上下文).文本主题.body 1!.color),
新:图标(图标.搜索,颜色:主题.of(上下文).文本主题.正文文本1!.颜色),

8zzbczxx

8zzbczxx5#

伙计们通常我们在导入之前添加依赖项。但在这种情况下,首先导入该文件(import 'package:charts_flutter/flutter.dart' as charts;)鼠标悬停在packages上后,它会给予一个添加依赖项选项,然后以这种方式添加依赖项。

相关问题