freezed icon indicating copy to clipboard operation
freezed copied to clipboard

Add field name strings as static members of class to avoid typing them manually when needed

Open dannnnthemannnn opened this issue 5 years ago • 5 comments

https://gist.github.com/dannnnthemannnn/f22b94c586c26a0909be073d2cceed42

@freezed
abstract class Discussion with _$Discussion {
  factory Discussion({
    DateTime scheduledTime,
    bool isPublic,
    List<String> participantIds,
  }) = _Discussion;
  
  // Add Helper field name somehow to generated class similar to this:
  static const scheduledTimeField = 'scheduledTime';
  static const isPublicField = 'isPublic';
  static const participantIds = 'participantIds';
}

dannnnthemannnn avatar Sep 03 '20 17:09 dannnnthemannnn

This could be added to the generated $Discussion class, such that we have:

print($Dicussion.nameOf.scheduledTime) // scheduledTime

rrousselGit avatar Sep 03 '20 17:09 rrousselGit

I want this feature too 👀

mono0926 avatar Sep 04 '20 00:09 mono0926

Would this make more sense on json_serializable as this is probably most used with json serialization/deserialization?

dannnnthemannnn avatar Sep 05 '20 23:09 dannnnthemannnn

Would love to have it as well.

deimantasa avatar Aug 19 '21 14:08 deimantasa

Hey, this would be great. Is there any way I could help? Beside PR? I feel that it would take too much time for me to dive into your codebase.

I am certainly going to donate once this is the feature in freezed package :-)

Thanks for consideration!

jan-siroky avatar May 03 '22 17:05 jan-siroky

I have no plan to implement this, so closing.

IMO this is not the responsibility of Freezed, and should instead be done by a separate code-generator.

rrousselGit avatar May 24 '23 14:05 rrousselGit