1

When I am using Text widget, there are two ways from which I can change style of widget

  1. Passing TextStyle to style permeter.
  2. Passing Theme.of(context).textTheme.titleLarge to style permeter.

when using first method I can use const keyword in front of Text widget and in second cannot. does using first method give me performance boost ?

I know using second method my code will be more organised. Which method should I use ?

Text("Select a City",style: Theme.of(context).textTheme.titleLarge,),

const Text("Select a City",style: TextStyle(fontSize: 22, color:Colors.grey)),

Thanks

Umesh P
  • 228
  • 2
  • 7
Manish Moond
  • 66
  • 1
  • 6

1 Answers1

0
  1. const makes that widget not to be rebuild when you call setState or otherwise, it can help you increase performance.

  2. You should use method 2 because it synchronizes your application, making it easy to change the theme mode

  • Does this helps [How to add link or code in comment area](https://stackoverflow.com/questions/53492705/does-using-const-in-the-widget-tree-improve-performance) – MenTalist May 25 '23 at 12:06