Sub6Resources / flutter_html

A Flutter widget for rendering static html as Flutter widgets (Will render over 80 different html tags!)
https://pub.dev/packages/flutter_html
MIT License
1.8k stars 861 forks source link

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

Open michalsrutek opened 4 months ago

michalsrutek commented 4 months ago

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 commented 4 months ago

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 - https://github.com/Sub6Resources/flutter_html/blob/79ec194fa6690e5caba58f5eca04e6748394bb6b/lib/src/style.dart#L280

TheManuz commented 4 months ago

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

adetorodev commented 3 months ago

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 commented 2 months ago

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 commented 2 months ago

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

chtgupta commented 1 month ago

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 commented 1 month ago

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