Ad

The Argument Type 'TextTheme' Can't Be Assigned To The Parameter Type 'Color'

I have a TabBar in which I am using labelColor, I am trying to migrate accentTextTheme, Currently my labelColor is LIKE THIS:

labelColor:
Theme.of(context).accentTextTheme.headline4.color,

I trying to migrate accentTextTheme like this from the flutter docs.

Code before migration:

TextStyle style = Theme.of(context).accentTextTheme.headline1;

Code after migration:

final ThemeData theme = Theme.of(context);
TextStyle style = theme.textTheme.headline1.copyWith(
  color: theme.colorScheme.onSecondary,
),

but when I try to implement it I get this error:

The argument type 'TextTheme' can't be assigned to the parameter type 'Color'.

Is there any way to migrate this without getting this error?

Ad

Answer

labelColor takes a Color and you are providing TextStyle,

    final ThemeData theme = Theme.of(context);
    TextStyle style = theme.textTheme.headline1!.copyWith(
      color: theme.colorScheme.onSecondary,
    );

    return Scaffold(
      body: Column(
        children: [
          TabBar( // just test for warring 
            labelColor: style.color,
            tabs: [],
          ),
          Text(
            "asda",
            style: style,
          ),

does it solve the issue?

Ad
source: stackoverflow.com
Ad