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

Idea of copyWith and initial #42

Open
UlasKasim opened this issue Nov 13, 2019 · 2 comments
Open

Idea of copyWith and initial #42

UlasKasim opened this issue Nov 13, 2019 · 2 comments
Labels
enhancement New feature or request question Further information is requested

Comments

@UlasKasim
Copy link

When i am about to create a model, i write json to dart and use your repository, then add my copyWith and initial, lets say we have A model it contains

class A{
    String b;
    String c;
}

I generate your json to dart and add these

A copyWith({String b, String c}) {
    return A(
        b: b ?? this.b,
        c: c ?? this.c
        );
  }
factory A.initial(){
    return A(b:"", c:"");
}

I know that im asking this because of my lazyness but u can generate these for everyone(mostly me)

@javiercbk
Copy link
Owner

Thanks for your contribution.

This is not hard to do but the most valuable contribution here is you use case. I've created this tool to quickly generate a parser for JSON API, but you are using this tool to actually crate classes in dart, am I right?

If this is the case, I wasn't really considering this tool for such scenario but I would like to understand why would you prefer writing JSON instead of writing the dart class. What does this tool offer that makes it more convenient for you to write JSON than plain dart?

Thanks for your feedback

@javiercbk javiercbk added enhancement New feature or request question Further information is requested labels Nov 15, 2019
@maks
Copy link

maks commented Nov 20, 2019

For me this would be fantastic in conjunction with #43 , as this is exactly how I currently have my hand written data model classes with hand written fromJson(), toJSON(), so I could then just use the convertor to completely generate all my currently hand written classes.

I think the key to this usecase is knowing that the generated classes are use as immutable data models, so having copyWith (and to lesser extent initial) would be a huge help. I suspect this would be common practise for Android developers coming from using Kotlin data classes in this manner.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants