Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Error: The getter 'headline1' isn't defined for the class 'TextTheme'. after upgrading to Flutter 3.22 #1422

Open
michalsrutek opened this issue May 14, 2024 · 7 comments
Labels
bug Something isn't working

Comments

@michalsrutek
Copy link
Contributor

Describe the bug:

Upon upgrading Flutter to 3.22, we're getting

flutter_html-3.0.0-alpha.6/lib/style.dart:253:51: Error: The getter 'headline1' isn't defined for the
class 'TextTheme'.

as it has been deprecated for a long time and finally removed in this release.

Expected behavior:

No build errors.

Stacktrace/Logcat

flutter_html-3.0.0-alpha.6/lib/style.dart:253:51: Error: The getter 'headline1' isn't defined for the
class 'TextTheme'.
Screenshot 2024-05-14 at 6 33 18

A picture of a cute animal (not mandatory but encouraged)

Screenshot 2024-05-14 at 6 33 51
@michalsrutek michalsrutek added the bug Something isn't working label May 14, 2024
@michalsrutek
Copy link
Contributor Author

Looks like this is an issue in 3.0.0-alpha.6, but not an issue in 3.0.0-beta.2 - as can be seen here -

static Map<String, Style> fromThemeData(ThemeData theme) => {

@TheManuz
Copy link

Thanks @michalsrutek, I solved using 3.0.0-beta.2

@adetorodev
Copy link

I have having this issue.
I have try several version including 3.0.0-beta.2 3.0.0-alpha.5 3.0.0-alpha.6

../../.pub-cache/hosted/pub.dev/flutter_html-3.0.0-alpha.5/lib/html_parser.dart:153:62: Error: The getter 'bodyText2' isn't defined for the class 'TextTheme'.
 - 'TextTheme' is from 'package:flutter/src/material/text_theme.dart' ('../../Android/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 'bodyText2'.
      style: Style.fromTextStyle(Theme.of(context).textTheme.bodyText2!),
                                                             ^^^^^^^^^
../../.pub-cache/hosted/pub.dev/flutter_html-3.0.0-alpha.5/lib/html_parser.dart:217:72: Error: The getter 'bodyText2' isn't defined for the class 'TextTheme'.
 - 'TextTheme' is from 'package:flutter/src/material/text_theme.dart' ('../../Android/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 'bodyText2'.
                style: Style.fromTextStyle(Theme.of(context).textTheme.bodyText2!),
                                                                      ^^^^^^^^^
../../.pub-cache/hosted/pub.dev/flutter_html-3.0.0-alpha.5/lib/style.dart:239:47: Error: The getter 'headline1' isn't defined for the class 'TextTheme'.
 - 'TextTheme' is from 'package:flutter/src/material/text_theme.dart' ('../../Android/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 'headline1'.
    'h1': Style.fromTextStyle(theme.textTheme.headline1!),
                                              ^^^^^^^^^
../../.pub-cache/hosted/pub.dev/flutter_html-3.0.0-alpha.5/lib/style.dart:240:47: Error: The getter 'headline2' isn't defined for the class 'TextTheme'.
 - 'TextTheme' is from 'package:flutter/src/material/text_theme.dart' ('../../Android/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 'headline2'.
    'h2': Style.fromTextStyle(theme.textTheme.headline2!),
                                              ^^^^^^^^^
../../.pub-cache/hosted/pub.dev/flutter_html-3.0.0-alpha.5/lib/style.dart:241:47: Error: The getter 'headline3' isn't defined for the class 'TextTheme'.
 - 'TextTheme' is from 'package:flutter/src/material/text_theme.dart' ('../../Android/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 'headline3'.
    'h3': Style.fromTextStyle(theme.textTheme.headline3!),
                                              ^^^^^^^^^
../../.pub-cache/hosted/pub.dev/flutter_html-3.0.0-alpha.5/lib/style.dart:242:47: Error: The getter 'headline4' isn't defined for the class 'TextTheme'.
 - 'TextTheme' is from 'package:flutter/src/material/text_theme.dart' ('../../Android/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 'headline4'.
    'h4': Style.fromTextStyle(theme.textTheme.headline4!),
                                              ^^^^^^^^^
../../.pub-cache/hosted/pub.dev/flutter_html-3.0.0-alpha.5/lib/style.dart:243:47: Error: The getter 'headline5' isn't defined for the class 'TextTheme'.
 - 'TextTheme' is from 'package:flutter/src/material/text_theme.dart' ('../../Android/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 'headline5'.
    'h5': Style.fromTextStyle(theme.textTheme.headline5!),
                                              ^^^^^^^^^
../../.pub-cache/hosted/pub.dev/flutter_html-3.0.0-alpha.5/lib/style.dart:244:47: Error: The getter 'headline6' isn't defined for the class 'TextTheme'.
 - 'TextTheme' is from 'package:flutter/src/material/text_theme.dart' ('../../Android/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 'headline6'.
    'h6': Style.fromTextStyle(theme.textTheme.headline6!),
                                              ^^^^^^^^^
../../.pub-cache/hosted/pub.dev/flutter_html-3.0.0-alpha.5/lib/style.dart:245:49: Error: The getter 'bodyText2' isn't defined for the class 'TextTheme'.
 - 'TextTheme' is from 'package:flutter/src/material/text_theme.dart' ('../../Android/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 'bodyText2'.
    'body': Style.fromTextStyle(theme.textTheme.bodyText2!),

3.0.0-beta.2 and 3.0.0-beta.1 throw error with this line of code:

SelectableHtml(
      data: htmlController.htmlText,
      shrinkWrap: true,
       onLinkTap: (String? url,
        RenderContext context,
         Map<String, String> attributes,
                 element) {
                  if (url!.startsWith('www.')) {
                     url = 'https://$url';
                   }
                  if (kDebugMode) {
                        print('Redirect to url: $url');
                  }
                 html.window.open(url, "_blank");
                 },
 ),

That's on SelectableHtml and RenderContext

@julienmiclo
Copy link

julienmiclo commented Jul 18, 2024

Hello,
i have the same problem.

I found why it cause by naming arguments of fromThemeData() because 'package:flutter/material.dart' change name of this :

It's now (2022-08-18) here :

headline1 => displayLarge
headline2 => displayMedium
headline3 => displaySmall
headline4 => headlineMedium
headline5 => headlineSmall
headline6 => titleLarge
bodyText2 => bodyMedium

How can i override this function for fixing temporary this bug ?
Thank you.

@dLeff
Copy link

dLeff commented Jul 23, 2024

@julienmiclo , could be fixed using 3.0.0-beta.2 version of the package ;)

@chtgupta
Copy link

Looking at this PR (https://github.com/flutter/flutter/pull/109817/files#diff-a8a9a3cded64a0f45ac193fd0d6654c2c8ede69600c4c0773a282a68169a6dbd)
And the file (packages/flutter/test_fixes/material.dart.expect)

I created an extension file that adds the backward compatibility. Just add this files to your project and import wherever you get the error.
https://gist.github.com/chtgupta/8943b4772025ec78afc748e2476efef5

@cgs
Copy link

cgs commented Aug 23, 2024

If I upgrade to 3.0.0-beta.2 it solves the getter errors, but creates a bigger problem for me as I'm using CustomRender all over the place. And almost all the errors are pointing to flutter_html libs, not my code. As the docs are currently pretty sparse on how to migrate from using CustomRender, I forked alpha.6 and added @chtgupta's fix to keep my app running.

pubspec.yml:

  flutter_html:
    git:
      url: https://github.com/cgs/flutter_html
      ref: alpha-6-flutter-322

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

7 participants