Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to change color of text and icons on appbar flutter

Tags:

flutter

dart

I am having problem while changing the color of text and icon widgets on appbar in flutter.

I have tried theme inside the material app but it's not working.

where this is working : title: Text('Profile', style: TextStyle(color: Colors.black)), But I want to apply this for all appbars. So where should I make changes in material theme.

MaterialApp(
          title: "My App",
          theme: ThemeData(
            appBarTheme: AppBarTheme(
              backgroundColor: Color(0xffFCD581),
              brightness: Brightness.dark,
            ),

enter image description here

how can i change the color of text: profile and icon . globally.

setting color of headline6 to Colors.black works. but it's also making the title text smaller. I can set the fontsize in headline6 and it reflects universally. But I think the default size of title that we get with appbar is suitable enough. So is there any solution that will only change the color of the appbar text, title without affecting the fontsize.

like image 278
Dhananjay Gavali Avatar asked Oct 27 '25 05:10

Dhananjay Gavali


1 Answers

Use IconButton as the back button and assign color, for Title use TextStyle and assign a color.

1. Using AppBar:

Scaffold(
      appBar: AppBar(
        backgroundColor: Colors.white,
        leading: IconButton(
          icon: Icon(Icons.arrow_back, color: Colors.red),
          onPressed: () => Navigator.of(context).pop(),
        ),
        title: Text("Sample", style: TextStyle(color: Colors.red),),
        centerTitle: true,
      ),

2. Using ThemeData:

theme: ThemeData(
    primaryTextTheme: TextTheme(
      headline6: TextStyle(color: Colors.red),
    ),
    appBarTheme: AppBarTheme(
      iconTheme: IconThemeData(color: Colors.red),
    ),
  ),

Output:

enter image description here

like image 53
Jitesh Mohite Avatar answered Oct 28 '25 19:10

Jitesh Mohite



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!