Skip to content

Feature Request (dart-generator): Add copyWith method in data classes #626

Description

@daniloapr

This is feature request is a improvement proposal for adding a copyWith method that would allow changing the ApiClient's objects without depending directly on them.

Example:

class User {
  final String id;
  final String name;

  const User({
    required this.id,
    required this.name,
  });
  
  User copyWith({
    String? id,
    String? name,
  }) {
    return User(
      id: id ?? this.id,
      name: name ?? this.name,
    );
  }
}

Use case:

// get user from api
final user = await apiClient.getUser();

// update user name keeping the id
final updatedUser = user.copyWith(name: 'New Name');
await apiClient.updateUser(newUser);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions