8

I can't change my AppBar title text color using AppBar titleTextStyle. I know I can set the AppBar title style in some ways like using style in textWidget or set the textTheme in AppBar, but I just wanna know why it cannot be changed by setting titleTextStyle.

The code is below. AppBar title is still white though setting the titleTextStyle and the foregroundColor.

class MyStatelessWidget extends StatelessWidget { const MyStatelessWidget({Key? key}) : super(key: key); @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( foregroundColor: Colors.black, titleTextStyle: TextStyle(color: Colors.black), title: const Text('AppBar Color'),), body: const Center( child: Text('sample'), ), ); } } 
2
  • Your code has an extra comma for title, it doesn't compile, could be why your change isn't taking effect Commented Mar 19, 2021 at 3:26
  • I'm sorry for not formatting and it not being easy to read, but I think the comma is not extra. Commented Mar 19, 2021 at 4:28

4 Answers 4

12

i know this question is for 1 month ago, but answer to this question is :

using backwardsCompatibility: false, for AppBarTheme

appBarTheme: AppBarTheme( backwardsCompatibility: false, titleTextStyle: TextStyle( color: Colors.red, ), ), 

or antother way :

appBarTheme: AppBarTheme( textTheme: TextTheme( headline6: TextStyle( color: Colors.red, ) ) ), 
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for the 'backwardsCompatibility:false'. As mentioned in api.flutter.dev/flutter/material/AppBarTheme-class.html: "app developers are encouraged to opt into the new features by setting it to false and using the foregroundColor and systemOverlayStyle properties as needed. AppBar.textTheme is obsolete". By the way, if you want to change only the text color, foregroundColor is enough, titleTextStyle is not needed.
1

I think you need to remove const for the title

@override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( foregroundColor: Colors.black, titleTextStyle: TextStyle(color: Colors.black), title: Text('AppBar Color'), ), body: const Center( child: Text('sample'), ), ); } 

2 Comments

Thank you, but It doesn't work at least for me.
titleTextStyle is a new prop. To make it work, u need to set backwardsCompatibility to false so that it will use the new prop. See the @DJafari 's answer
0

If you only want to change the AppBar title Text color, then this might help you:

appBar: AppBar( title: Text( 'To Do List', style: TextStyle(color: Colors.black), ), ), 

enter image description here

Comments

0

You can add this style to the AppBarTheme

 appBarTheme: AppBarTheme( backgroundColor: Colors.yellow, titleTextStyle: TextStyle(color: Colors.black,fontSize: 20), backwardsCompatibility: false,) 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.