Open tranhuongk opened 2 years ago
@hiranthaR
@hiranthaR I just released an add-on for our team to use. if you don't intend to merge my pull request then let me know so i can officially release it as a copy. https://marketplace.visualstudio.com/items?itemName=HuongTran.json-to-dart-enhanced
@tranhuongk Hi 👋 It's great to see people who want to join and help create a good product together. I'm on vacation right now and don't have a chance to check the code. I want to explain that this generator follow code guide style by Dart team and Dart style. I don't know reason why you want change as default with non cast type. But would be nice to keep default style as Dart team. Maybe it would be better to add a option to change non cast type. It would make this extention more customable. What do you think? Have you time for this?
It's my fault. I should to add collaboration rules in the documentation to save time for developers in your case you need rewrite code to add option.
@tranhuongk What about your extension. Of course you can clone and make your own becouse it's open source. When your have a good product it's not possible avoid dublicates in the market. This extension also based on old and non supporting open source. But if you want make a good product it's better it make with team 😉
@tranhuongk Hi 👋 It's great to see people who want to join and help create a good product together. I'm on vacation right now and don't have a chance to check the code. I want to explain that this generator follow code guide style by Dart team and Dart style. I don't know reason why you want change as default with non cast type. But would be nice to keep default style as Dart team. Maybe it would be better to add a option to change non cast type. It would make this extention more customable. What do you think? Have you time for this?
It's my fault. I should to add collaboration rules in the documentation to save time for developers in your case you need rewrite code to add option.
That is a good plan. I am having some error with code generation, when one of my variables in code generation is returned as an int but the data can also be returned as a double for example. then my model will get error can't assign that variable to int?. above is my whole attempt to get the model to run with whatever data is returned from the api.
I am having some error with code generation, when one of my variables in code generation is returned as an int but the data can also be returned as a double for example. then my model will get error can't assign that variable to int?. above is my whole attempt to get the model to run with whatever data is returned from the api.
You should not modify function addType
in the ClassDefinition
because it is top function, avoid it. I recommend don't touch it. Handle your code as deep as possible before print.
@tranhuongk
@iamarnas yes. Can you update it? It time I so busy with my project. Or I will update and push it after Aug. Thank you!!
@iamarnas is this ready to deploy? :)
@iamarnas is this ready to deploy? :)
Hi @hiranthaR 👋
No, not really. Here is no changes just type casting in the another way by removing as
keyword. The as
is considered the safest form of typecasting in dart, and it is used quite often in Flutter UI, particularly when using the bloc library. The current type casting style for this generator is based on Dart team, equal to json_serializable
package created by Dart team and I think is best rules to follow theys Dart style. This pull requests woul break Dart team style. Another problem I saw here is removed error check for unimplemented methods where changed to return empty object instead. My opinion is that you can close this pull requests, here is already published dublicate in the marketplace with these changes, by name Json to Dart Model Enhanced.
Change: json as int -> int.tryParse(json.toString()) json as double -> double.tryParse(json.toString()) json as String? -> json?.String() json as List? -> List.from(json) json as Map? -> Map.from(json)