ReinBentdal / styled_widget

Simplifying widget style in Flutter.
https://pub.dev/packages/styled_widget
MIT License
1.27k stars 103 forks source link

How to adjust text height? #39

Closed fedotxxl closed 4 years ago

fedotxxl commented 4 years ago

Do you have support for the height property of TextStyle (https://stackoverflow.com/a/58156970/716027)?

ReinBentdal commented 4 years ago

No, not as a method. I am kinda moving away from methods which modifies a previously defined widget, like all the text widgets. All thought i havent messuered the performance loss i would rather be on the safe side and define the text style withing the Text widget. The reason its less performant is because when you call a method which modifies the Text widget, it copies the old styled and applies the new ones before rendering a new Text widget. This is the only possibility since the Text widget is immutable. Therefore i would recommend defining your text style within the Text widget instead.

final TextStyle _textStyle = TextStyle(/* style */);

Text('text', style: _textStyle)
  . //style
fedotxxl commented 4 years ago

So your suggestion is to use TextStyle for text and extension methods for other cases?

ReinBentdal commented 4 years ago

yes, and the same goes for Icon. I might remove them in the future.

When using multiple DecoratedBox styles i would also recommend using decorated() instead of listing each up by their respective method:

from

Widget()
  .backgroundColor(Colors.blue)
  .boxShadow()

to

Widget()
  .decorated(
    color: Colors.blue,
    boxShadow: BoxShadow()
  )
fedotxxl commented 4 years ago

Ok, I see. The first approach might have a performance penalty but is it critical in the common app?... It's better to provide simple and usable API which will work in 90% of cases and document the other 10% of cases.

ReinBentdal commented 4 years ago

I`m not sure how it actually impacts the performance. Would be interesting to actually test the difference. Probably not a big difference.