Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use the flutter_class_parser package to simplify the parsing #62

Open
KevinVan720 opened this issue Mar 18, 2021 · 0 comments
Open

Use the flutter_class_parser package to simplify the parsing #62

KevinVan720 opened this issue Mar 18, 2021 · 0 comments

Comments

@KevinVan720
Copy link

KevinVan720 commented Mar 18, 2021

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant