Flutter Best Practices
Color and Style: global const vs theme
I searched for Flutter articles today and found Derrit Mwiti’s article with the Title ‘Flutter Development Best Practices’. I’m learning flutter since January 2020 and think it’s crucial not to get used to bad habits. Therefore such articles are very interesting for me. Most of the practices recommended by Derrit I can understand. But the first one in his list made me doubt.
Are themes really that great?
He begins with the advice to use themes and points out the following advantages:
- It’s easier to reference properties anywhere in the code
- It prevents code repetition
- It’s easier to adjust a property at one place and see the change everywhere.
Then he gives some code samples to show how the themes are defined and how they are used.
This is all well and good, but it occurred to me that all these advantages can also be achieved with simple global constants. I saw these globals first in the source code of Dane Mackier on github. In his project 014 he defines colors and fonts with global constants in files like app_colors.dart and textstyles.dart.
I found a similar practice in Angela Yu’s great flutter course on Udemy. She has a file called…