How to change text color of AppBar, icon color of FAB universally using theme?

I used a slightly different technique, I didn't use a theme, I just customized its appearance, so that when I created it looked like this:

appBar: new AppBar(
  iconTheme: IconThemeData(
    color: Colors.white
  ),
  title: const Text('Saved Suggestions', style: TextStyle(
    color: Colors.white
  )),
  backgroundColor: Colors.pink,
),

Here is the way you can set the AppBar Title color.

return new MaterialApp(
  theme: Theme.of(context).copyWith(
      accentIconTheme: Theme.of(context).accentIconTheme.copyWith(
        color: Colors.white
      ),
      accentColor: Colors.amber,
      primaryColor: Colors.amber,
      primaryIconTheme: Theme.of(context).primaryIconTheme.copyWith(
        color: Colors.white
      ),
      primaryTextTheme: Theme
          .of(context)
          .primaryTextTheme
          .apply(bodyColor: Colors.white)),
  home: Scaffold(
    appBar: AppBar(
      title: Text("Theme Demo"),
      leading: IconButton(
        onPressed: (){},
        icon: Icon(Icons.menu),
      ),
    ),
    floatingActionButton: FloatingActionButton(
      child: Icon(Icons.add),
    ),
  ),
);

So far the solution I tested is using a foregroundColor in appBarTheme

This worked fine for me Universally

MaterialApp(
     theme: ThemeData(
          appBarTheme: AppBarTheme(
          backgroundColor: Colors.blue,
          foregroundColor: Colors.white //here you can give the text color
          )
     )
)

enter image description here

MaterialApp(
     theme: ThemeData(
          appBarTheme: AppBarTheme(
          backgroundColor: Colors.white,
          foregroundColor: Colors.black//here you can give the text color
          )
     )
)

enter image description here


I think the most straightforward way of doing this is to adjust the title color for the theme that you are working with:

theme: new ThemeData(
  primarySwatch: Colors.grey,
  primaryTextTheme: TextTheme(
    headline6: TextStyle(
      color: Colors.white
    )
  )
)

Tags:

Flutter