-
Notifications
You must be signed in to change notification settings - Fork 23
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
Enum string needs to be exactly the same as enum name #15
Comments
Hey @ajsaraujo So I wasn't sure about this and wanted to think about it which is why I have taken so long to get back to you. Of course, I just came across this issue myself! Because the EnumToString class is static, where were you going to store the mapping? We could consider making it a singleton and I'm not sure what implications that might have on the community. If its a singleton but the parse function is static that might also have some issues (cant reference instance members). None of this is insurmountable but this package is used incredibly widely so I want to make sure if we deliver a new function its done in an elegant way. I really like the proposed syntax though! Like I said, I need to do something similar myself, so I will have a go and see what learnings I get from it. Any thoughts from the community? |
It would be nice if EnumToString was a Singleton, so we could store state (the mapping) in it, but as you suggested we don't know what impacts that may have on the API usage. Another solution would be storing this somewhere else. It could be a global variable inside the So in the second case the parse method would be like this: static String parse(enumItem, {bool camelCase = false}) {
if (enumItem == null) return null;
// Get mock will return null if a mock doesn't exist for enumItem.
final enumState = EnumGlobalState();
final mock = enumState.getMock(enumItem);
if (mock != null) return mock;
final _tmp = enumItem.toString().split('.')[1];
return !camelCase ? _tmp : camelCaseToWords(_tmp);
} We could have separate functions to check mock existence and value, such as In the other hand I don't know what would be best for |
I want to use your package in my app, but right now it won't fit my needs, since one of my enums should be converted to the string
'PG-13'
. However, you can't have an enum namedPG-13
, because you can't have a hyphen in your enum name.It would be nice if you could mock enum string values, for example:
I would be happy to submit a PR with this functionality if you would like.
The text was updated successfully, but these errors were encountered: