Reputation: 2051
The TextStyle
class in Flutter requires fontSize
to be constant.
Let's say I already created the constant value in widget A
. Now I want to pass the value to widget B
and inside B
I want to use that like following:
const textStyleInB = TextStyle(fontSize: this.iconWidth);
How can I achieve this?
Upvotes: 1
Views: 1036
Reputation: 77354
The TextStyle class in Flutter requires fontSize to be constant.
No, it doesn't.
final textStyleInB = TextStyle(fontSize: this.iconWidth);
Now, if you want things to be const
(so, a compile time constant, instead of final
, a run time constant), then yes, you cannot have a variable for that that is set at runtime. Obviously, a compile time constant can only be set at compile time.
Upvotes: 1