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
Different case in flat map #47
Comments
Hi, Did you configure key_case: camel
key_map_case: pascal
flat_map: false
maps:
- projectActivityType
- addressBookType |
Thanks, but still doesn't seem to work as we expect. With following example we'd expect the flat map will be generted just for maps mentioned in the list. Neither of them work. None of the maps is generated. We'd expect the regular keys be converted into camel case, and maps for these objects generated with Pascal case. key_case: camel
key_map_case: pascal
flat_map: false
maps:
- ProjectActivityType
- AddressBookType
- addressBookType |
You mean this following map?
Then Actually, I don't know exactly what you are going to do... If you want to access the keys dynamically, then this should be enough: final t = Translations.of(context);
String a = t.projectActivityType['Company']; // Company because pascal case is applied Just to make sure: |
It seems to be alright on my side. |
Sorry @Tienisto , but I am still having issues. My config is: key_case: camel
key_map_case: snake
flat_map: true
maps:
- ProjectActivityType
- AddressBookType
- FieldType But unfortunately the maps in strings.g.dart are still translated to:
In .json file we have following: "FieldType": {
"LPLATE": "License plate",
"DESC": "Description",
"CONTACT_INVESTOR": "Contact Investor", I would expect the map keys to be in snake case but it's not. But our use case is different. We'd like to use camel case but ONLY for maps to disable any text transformations. Reason is we use enums like: // The key will be "FieldType.LPLATE"
labelText: t[FieldType.LPLATE.toString()] |
Alright, currently, it is not possible to have different cases.
I think a new configuration |
I think there is no elegant solution for your problem.
The best solution would be to use the new dart enum feature: Then use the following config: key_case: pascal
# do not set key_map_case, so we retain the UPPERCASE_SNAKE case
maps:
- FieldType Will generate: Map<String, String> get FieldType => {
'LPLATE': 'License plate',
'DESC': 'Description',
'CONTACT_INVESTOR': 'Contact Investor',
}; Usage: String a = t.FieldType['CONTACT_INVESTOR'];
String b = t.FieldType[FieldType.LPLATE.name]; |
Affected version: 5.6.0
Setting following in build.yaml does not seem to have effect on generated maps case:
key_map_case
case transformation is ignored.JSON:
will produce nin strings.g.dart:
The text was updated successfully, but these errors were encountered: