I upgraded version my flutter project to 3.0.0 in order to use null safety feature. When I run the project I got Cannot mix 2018 and 2021 terms in call to TextTheme() constructor. error.
Cannot mix 2018 and 2021 terms in call to TextTheme() constructor. 'package:flutter/src/material/text_theme.dart': package:flutter/…/material/text_theme.dart:1 Failed assertion: line 118 pos 10: '(displayLarge == null && displayMedium == null && displaySmall == null && headlineMedium == null && headlineSmall == null && titleLarge == null && titleMedium == null && titleSmall == null && bodyLarge == null && bodyMedium == null && bodySmall == null && labelLarge == null && labelSmall == null) || (headline1 == null && headline2 == null && headline3 == null && headline4 == null && headline5 == null && headline6 == null && subtitle1 == null && subtitle2 == null && bodyText1 == null && bodyText2 == null && caption == null && button == null && overline == null)'
Does anyone know what I should do?
@mister_cool_beans is correct.
Flutter is transitioning to Material 3 text style names for TextTheme. We are in the awkward period where both sets exist. See more here for the commit associated with the change.
To be more clear, you must only use terms from the 2018 set or from the 2021 set. Update your TextTheme/ThemeData correspondingly. I suggest you take the opportunity to upgrade to 2021.
2021 set
displayLarge, displayMedium, displaySmall
headlineLarge, headlineMedium, headlineSmall
titleLarge, titleMedium, titleSmall
bodyLarge, bodyMedium, bodySmall
labelLarge, labelMedium, labelSmall
2018 set
headline1, headline2, headline3, headline4, headline5, headline6
subtitle1, subtitle2
bodyText1, bodyText2
caption, button, overline
As @Partick mentioned, if you scroll down to the implementation seen here you can see the sets defined in code.
...
}) : assert(
(displayLarge == null && displayMedium == null && displaySmall == null && headlineMedium == null &&
headlineSmall == null && titleLarge == null && titleMedium == null && titleSmall == null &&
bodyLarge == null && bodyMedium == null && bodySmall == null && labelLarge == null && labelSmall == null) ||
(headline1 == null && headline2 == null && headline3 == null && headline4 == null &&
headline5 == null && headline6 == null && subtitle1 == null && subtitle2 == null &&
bodyText1 == null && bodyText2 == null && caption == null && button == null && overline == null),
'Cannot mix 2018 and 2021 terms in call to TextTheme() constructor.'
),
...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With