dynamic_widget icon indicating copy to clipboard operation
dynamic_widget copied to clipboard

Use the flutter_class_parser package to simplify the parsing

Open KevinVan720 opened this issue 4 years ago • 0 comments

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?

KevinVan720 avatar Mar 18 '21 16:03 KevinVan720