Cannot mix 2018 and 2021 terms in call to TextTheme() constructor

1,147

@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 
headlineMedium, headlineSmall 
titleLarge, titleMedium, titleSmall 
bodyLarge, bodyMedium, bodySmall 
labelLarge, 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.'
     ),
...
Share:
1,147
efesezer
Author by

efesezer

A Fenerbahce fan who is eager to solve the problems

Updated on January 04, 2023

Comments

  • efesezer
    efesezer over 1 year

    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
      mister_cool_beans almost 2 years
      go to your ThemeData() in your main.dart and modify TextTheme()
  • Patrick
    Patrick almost 2 years
    You are using styles that came from 2018 and those from 2021 you cannot use them both you must use one set or the other. Kind of like using the color property and box decoration on a container both are not allowed. You will notice from the error message that it checks if you follow this rule