[BUG] `Error: The getter 'headline1' isn't defined for the class 'TextTheme'.` after upgrading to Flutter 3.22
Opened this issue ยท 7 comments
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'.
A picture of a cute animal (not mandatory but encouraged)
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 -
flutter_html/lib/src/style.dart
Line 280 in 79ec194
Thanks @michalsrutek, I solved using 3.0.0-beta.2
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
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.
@julienmiclo , could be fixed using 3.0.0-beta.2 version of the package ;)
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
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