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

[Feature request] Generate static property to get key strings. #1018

Closed
normidar opened this issue Dec 13, 2023 · 1 comment
Closed

[Feature request] Generate static property to get key strings. #1018

normidar opened this issue Dec 13, 2023 · 1 comment
Assignees
Labels
enhancement New feature or request needs triage

Comments

@normidar
Copy link

Is your feature request related to a problem? Please describe.
Similer with #437

Describe the solution you'd like

I use key to access my Json after toJson() so I create codes like:

@freezed
class TaskDataset with _$TaskDataset {
  // ↓ here
  static const keyTask = 'task';
  static const keyIsDone = 'isDone';
  static const keyCreatedAt = 'createdAt';
  static const keyStared = 'stared';
  // ↑ here

  const factory TaskDataset({
    required String task,
    required bool isDone,
    required DateTime? createdAt,
    bool? stared,
  }) = _TaskDataset;

  factory TaskDataset.fromJson(Map<String, dynamic> json) =>
      _$TaskDatasetFromJson(json);
}

I need a way to generate them.

Describe alternatives you've considered
As above

Additional context
I search and find #437 , but I thing this issue is different.

@rrousselGit
Copy link
Owner

That's even worse than #437 :P

JSON logic isn't part of Freezed but json_serializable. Freezed won't do such a thing.

But to begin with, what you're asking is already part of json_serializable, under the name createFieldMap: https://pub.dev/documentation/json_annotation/latest/json_annotation/JsonSerializable/createFieldMap.html

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

No branches or pull requests

2 participants