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

Add a copyWith method to the Product object #852

Open
g123k opened this issue Dec 11, 2023 · 4 comments · May be fixed by #853
Open

Add a copyWith method to the Product object #852

g123k opened this issue Dec 11, 2023 · 4 comments · May be fixed by #853

Comments

@g123k
Copy link
Contributor

g123k commented Dec 11, 2023

Hi everyone,

The Product object has non-final fields, but when we want to use the Product class as immutable, each client must code it. It would be nice to integrate it directly into the SDK.

@teolemon
Copy link
Member

We should both be in bed ATM :-)

@monsieurtanuki
Copy link
Contributor

We should both be in bed ATM :-)

image

@monsieurtanuki
Copy link
Contributor

@g123k Currently in Smoothie we do copy Product data, in UpToDateProductProvider:

  // TODO(monsieurtanuki): move code to off-dart Product?
  Product copy(final Product source) => Product.fromJson(
        jsonDecode(jsonEncode(source.toJson())) as Map<String, dynamic>,
      );

Moving this copy code from Smoothie to off-dart would be much less painful than implementing copyWith, and would provide the same feature as all fields are not final and nullable.

@g123k
Copy link
Contributor Author

g123k commented Dec 11, 2023

I didn't know about this in the app 👍
The only here would be to create a "real" copyWith, not something based on a json, that requires calls to jsonDecode/jsonEncode

@g123k g123k linked a pull request Dec 11, 2023 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging a pull request may close this issue.

3 participants