How to resolve Error: The getter 'body1' isn't defined for the class 'TextTheme' in flutter?
Asked Answered
M

7

8

My flutter application is not able to run on 2.5.0-5.3.pre beta version. after then I searched for it then need to upgrade my flutter sdk so have upgraded to latest beta version 2.6.0-5.2.pre but still getting errors. the errors with place_picker-0.9.19-nullsafety plugin. and not able to resolve it.

ERRORS LOG:

../../../../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

ERRORS:

enter image description here

MY CURRENT FUTTER VERSION:

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)
Mantel answered 24/9, 2021 at 9:7 Comment(4)
use bodyText1 insteadLovage
@Irsvmb you are saying , I have to edit plugins ?! Okay lemme try it.Mantel
@Irsvmb Thanks , It works. Actually I had never try to edit any plugins, always afraid of doing that.Mantel
The author should really be editing it. :)Dupe
W
5

I was dealing with this error. In my case, it was because there was a dependency that was not compatible with flutter 2.5. I tried many solutions. But only this worked for me.

First add this to your pubspec.yaml

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

as described on this link.

If you have an error saying: remote end hung up unexpectedly while git cloning,

then run this commands

git config --global http.postBuffer 500M
git config --global http.maxRequestBuffer 100M
git config --global core.compression 0 

as described on this answer.

This solved my problem.

Water answered 31/10, 2021 at 11:17 Comment(1)
While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - From ReviewAntlia
P
2

Add them in dependencies and remove body1 from bodyText1

charts_flutter:
    git:
      url: git://github.com/google/charts.git
      path: charts_flutter
Pfeffer answered 20/2, 2022 at 15:12 Comment(0)
K
1

Please use charts_flutter: ^0.12.0

Knives answered 15/12, 2022 at 2:9 Comment(0)
H
0

The error thrown on the logs seems to be thrown by the plugin that you're using: place_picker-0.9.19-nullsafety. The logs indicate that the issue comes from Theme.of(context).textTheme.body1

Checking the Flutter docs, body1 on TextTheme is defined as bodyText1. You might want to consider updating how body1 is being called in TextTheme. Otherwise, you can track this issue ticket filed on GitHub related to this issue.

Hebner answered 25/10, 2021 at 17:28 Comment(0)
I
0

Edit the lines in the dart package like below and it will work. Of course the author should do this, but you can edit it yourself as well :)

rich_suggestion.dart

Original: TextSpan(text: boldText, style: style.copyWith(color: Theme.of(context).textTheme.body1!.color)),

New: TextSpan(text: boldText, style: style.copyWith(color: Theme.of(context).textTheme.bodyText1!.color)),

search_input.dart

Original: Icon(Icons.search, color: Theme.of(context).textTheme.body1!.color),

New: Icon(Icons.search, color: Theme.of(context).textTheme.bodyText1!.color),

image

Ibanez answered 4/11, 2021 at 12:23 Comment(0)
A
0

replace all in files ctrl + shif+ r "Theme.of(context)" with => ThemeData()

Akerboom answered 16/7 at 5:24 Comment(0)
P
-1

Guys usually we add dependencies before importing. but in this case first import that file(import 'package:charts_flutter/flutter.dart' as charts;) after that hover on package, it will give a option to add the dependencies then add the dependencies in this way. then your error will be solved.

Pinnati answered 20/11, 2022 at 14:2 Comment(1)
As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.Correlate

© 2022 - 2024 — McMap. All rights reserved.