How to set default text style for appbar title in Flutter?

2,871

So you can do is create a method Method as mentioned below and then pass the value to it and later you just call these method where you want just check the code below:

you make another helper_widgets.dart and add the below method so that you can access it everywhere.

 Widget appBar(String title,/* you can pass various paramenters to appbar text customization such as fontsize and many more*/ ) {
    return AppBar(
      title: Text(
        title,
        style: TextStyle(color: Colors.red, fontSize: 14),
      ),
    );
  }

and later just call it in the AppBar Widget

Scaffold(
        appBar: appBar('Sample Application'),
);

Let me know if it works.

Share:
2,871
Hoang Trung Nguyen
Author by

Hoang Trung Nguyen

Updated on November 21, 2022

Comments

  • Hoang Trung Nguyen
    Hoang Trung Nguyen over 1 year

    I have a lot of screens that have an app bar, I always have to set the style for the app bar each time I create a new screen, it so boring. So, anyone knows how to set a custom app bar text style or if there is a solution to this problem?

    • kaboc
      kaboc about 4 years
      Pass in ThemeData with your desired text style set as primaryTextTheme to the theme argument of MaterialApp as in this answer: stackoverflow.com/a/52804265/12086560