Hoang Trung Nguyen
Hoang Trung Nguyen

Reputation: 509

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

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?

Upvotes: 2

Views: 3668

Answers (1)

Sagar Acharya
Sagar Acharya

Reputation: 3767

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.

Upvotes: 0

Related Questions