dynamic_widget
dynamic_widget copied to clipboard
Use the flutter_class_parser package to simplify the parsing
I would like to suggest you having a look at this package. It has a simpler way to serialize/deserialize enum classes. Instead of manually listing all the values, we can just do something like:
extension FontWeightToJson on FontWeight { String toJson() { return this.toString().stripFirstDot(); } }
this is an extension method that will strip the class name for you.
And for parsing, you can just use:
FontWeight? parseFontWeight(String? string) { FontWeight? rst; FontWeight.values.forEach((element) { if (string == element.toJson()) { rst = element; } }); return rst; }
What do you think?