I am able to set the background color of AppBar
to Colors.amber
. This automatically sets the text color to Black. I am aware of the accessibility i
You can set it with AppBarTheme
theme: new ThemeData(
textTheme: Theme.of(context).textTheme.apply(
appBarTheme: AppBarTheme(
textTheme: TextTheme(
// center text style
headline6: TextStyle(
color: Colors.black
),
// Side text style
bodyText2: TextStyle(color: Colors.black)
)
)
),
),
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,
),
title
of AppBar
uses headline6
and floatingActionBar
uses color from primarySwatch
. Though it is not documented in TextTheme
, but I tested it. For example : to have red FloatingActionButton
and blue title text in AppBar
your theme
inside MaterialApp
should look like the following :
MaterialApp(
theme: ThemeData(
primarySwatch: Colors.red,
appBarTheme: AppBarTheme(
textTheme: TextTheme(
headline6: TextStyle(
color: Colors.blue,
fontWeight: FontWeight.bold,
fontSize: 28.0,
),
),
),
),
)
Easy and efficient and, less code method. Use light theme with desired color.
theme: ThemeData.light().copyWith(
accentColor: Colors.amber,
primaryColor: Colors.amber,
),
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
)
)
)
Firstly I wanna let u know that there are 3 ways to set colors in flutter.
So u asked u wanna set color or text in app bar. So it works if u set color in style property of Text method. Let me show you how it works. And also I will show you 3 ways of setting color. It doesn't matter if u use theme property or not because setting color of Text works as diffrent. Thats way I didn't use Theme property in examples.
1th:
Scaffold(
appBar: AppBar(
title: Text("App Name",
style: TextStyle(color: Colors.colorname),);
2th :
Scaffold(
appBar: AppBar(
title: Text("App Name",
style: TextStyle(color: Color(0xffffff),));
3th :
Scaffold(
appBar: AppBar(
backgroundColor: Colors.white,
title: Text("App Name",
style: TextStyle(color: Color.fromRGBO(0, 0, 0, 0, 0),));