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

Change non-cast variable #95

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open

Conversation

tranhuongk
Copy link

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)

@tranhuongk tranhuongk changed the title change non-cast variable Change non-cast variable Aug 2, 2022
@tranhuongk
Copy link
Author

@hiranthaR

@tranhuongk
Copy link
Author

@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

@iamarnas
Copy link
Collaborator

iamarnas commented Aug 9, 2022

@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.

@iamarnas
Copy link
Collaborator

iamarnas commented Aug 9, 2022

@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
Copy link
Author

@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.

@iamarnas
Copy link
Collaborator

iamarnas commented Aug 9, 2022

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

@tranhuongk
Copy link
Author

@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!!

@hiranthaR
Copy link
Owner

@iamarnas is this ready to deploy? :)

@iamarnas
Copy link
Collaborator

@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.

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

Successfully merging this pull request may close these issues.

None yet

5 participants