onPrimary deprecation -> migration fail on Flutter 3.3.0

Viewed 47

In Flutter 3.3.0 primary should never used because of deprecation... by right clicking on primary I get a migration hint to change primary -> foregroundColor...

But the onPrimary property is also deprecated. The migration guide says: change onPrimary to foregroundColor (there is no onForegroundColor)... but there is the problem. onPrimary should be in high contrast to primary.

What is to do here?

Code Example:

ElevatedButtonThemeData getElevatedButtonTheme(ColorScheme colorScheme, TextTheme textTheme) => ElevatedButtonThemeData(
      style: ElevatedButton.styleFrom(
        shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(32)),
        elevation: 1,
        primary: colorScheme.secondary,
        onPrimary: colorScheme.onSecondary,
        textStyle: textTheme.button,
      ),
    );

update: by clicking in the flutter code I found a comment "..use disabledForegroundColor..."

1 Answers

Ok, it seems the comment was wrong... primary is backgroundColor and onPrimary is foreground

But only for ElevatedButtonThemeData

ElevatedButtonThemeData getElevatedButtonTheme(ColorScheme colorScheme, TextTheme textTheme) => ElevatedButtonThemeData(
      style: ElevatedButton.styleFrom(
        shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(32)),
        elevation: 1,
        backgroundColor: colorScheme.secondary,
        foregroundColor: colorScheme.onSecondary,
        textStyle: textTheme.button,
      ),
    );
Related