Im trying to store FontStyle Value and FontWeight Value in HIVE Database in Flutter as String Values. However while fetching the values, im facing the issue of not being able to convert String value to FontStyle or FontWeight Value. I could use If statements and achieve it but is there a way to convert String "FontStyle.italic" to FontStyle.italic?
Asked
Active
Viewed 266 times
0
-
Is there an Integer equivalent to those classes? Example FontWeight.w900 = 1001239(Some Integer) ? @JoãoSoares – Sarah Jackson Jan 11 '21 at 19:55
-
Is your issue just for FontStyle? Because there's only normal or italic. You could do a simple solution for it. – J. S. Jan 11 '21 at 20:03
1 Answers
0
FontStyle
is of type enum
, therefore you can't have an integer equivalence for it by default. However, since FontStyle
have only 2 constant names normal
and italic
, then you can create your own integer equivalent. For example normal
would be 0 and italic
would be 1.
Example:
// fontStyleInt is the int retreived from Hive (0 or 1)
int fontStyleInt;
// In the build
Text("Text", style: TextStyle(fontStyle: fontStyleInt == 0 ? FontStyle.normal : FontStyle.italic))

Mohammad Kurjieh
- 1,043
- 7
- 16