copy_with_extension icon indicating copy to clipboard operation
copy_with_extension copied to clipboard

Consider deprecating `copyWithNull`

Open f-person opened this issue 3 years ago • 1 comments

First of all, thanks for the package! It's pretty awesome and I use it in production when I don't need all the stuff generated by Freezed for some models.

Recently I discovered that copyWith now correctly supports nullification of nullable fields. I wonder if deprecating copyWithNull will benefit the users of the package who might not be aware of this feature.

There might be scenarios when copyWithNull is useful, however, I couldn't think of those, and I am going to replace all uses of copyWithNull in my project with raw copyWith

f-person avatar Feb 16 '22 22:02 f-person

I would also like to include a snippet from my codebase that uses copyWithNull to demonstrate how deprecating copyWithNull with a note that copyWith is probably all you need improve the code quality of projects using the package:

  void setCountry(Country? newCountry) {
    if (newCountry == null) {
      emit(state.copyWithNull(country: true));
    } else {
      emit(state.copyWith(country: newCountry));
    }
  }

I was checking for null to use copyWithNull and set it to null explicitly. Now this will look like just setting the variable:

  void setCountry(Country? newCountry) {
    emit(state.copyWith(country: newCountry));
  }

f-person avatar Feb 16 '22 22:02 f-person

I don't have a strong opinion on this, but I see it as a separate feature and would keep it as a status quo for now. Perhaps we could reconsider it in the future if more users experience similar problems.

numen31337 avatar Aug 03 '22 10:08 numen31337