![]() It’s not super readable either, the important stuff ( body, bold, italic, 1.6) represent only 15% of the characters, the rest is boilerplate. #LETTERSPACE TUTORIAL CODE#That’s a lot of code to just add bold, italic and tweak the letter spacing. Modifying a text style is actually pretty easy, using the copyWith API, it’s just kinda verbose: (fontWeight: FontWeight.bold, fontStyle: alic, letterSpacing: 1.6) There can be a lot of ‘one off’ styles in an app, and it would be nice to be able to easily tweak these styles on the fly… Dart Extensions to the rescue! While the above approach is an excellent foundation, it could still spiral out of control if you tried to define every single combination of bold/italic/character spacing. Ok, so that’s pretty good… but it can be better! That’s not only a lot more readable, it’s also is significantly easier to maintain as your project scales. With the above class, we can now define a Text widget like so: Text("I am Text.", style: TextStyles.body) Normally this is 1, but we can tweak it for different form factors. FontSizes.scale - A bit outside the scope of this article, but we like to expose a global scale modifier to our fonts.All styling code is consolidated in one tight package. ![]() We can change the font style, or font sizes globally, extremely easily and quickly. ![]() ![]() Why the get functions instead of variables? By using static functions, we can change these values at run-time for extremely fast iteration and tweaking. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |