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]: "empty" method in Dart #2608

Open
jonathanjohn47 opened this issue May 29, 2024 · 0 comments
Open

[FEATURE]: "empty" method in Dart #2608

jonathanjohn47 opened this issue May 29, 2024 · 0 comments

Comments

@jonathanjohn47
Copy link

jonathanjohn47 commented May 29, 2024

Consider the following class

import 'dart:convert';

AdminModel adminModelFromJson(String str) =>
    AdminModel.fromJson(json.decode(str));

String adminModelToJson(AdminModel data) => json.encode(data.toJson());

class AdminModel {
  String profilePicLink;
  String firstName;
  String lastName;
  String phone;
  String email;
  bool rememberMe;

  AdminModel({
    required this.profilePicLink,
    required this.firstName,
    required this.lastName,
    required this.phone,
    required this.email,
    required this.rememberMe,
  });

  AdminModel copyWith({
    String? profilePicLink,
    String? firstName,
    String? lastName,
    String? phone,
    String? email,
    bool? rememberMe,
  }) =>
      AdminModel(
        profilePicLink: profilePicLink ?? this.profilePicLink,
        firstName: firstName ?? this.firstName,
        lastName: lastName ?? this.lastName,
        phone: phone ?? this.phone,
        email: email ?? this.email,
        rememberMe: rememberMe ?? this.rememberMe,
      );

  factory AdminModel.fromJson(Map<String, dynamic> json) => AdminModel(
        profilePicLink: json["profile_pic_link"],
        firstName: json["first_name"],
        lastName: json["last_name"],
        phone: json["phone"],
        email: json["email"],
        rememberMe: json["remember_me"],
      );

  Map<String, dynamic> toJson() => {
        "profile_pic_link": profilePicLink,
        "first_name": firstName,
        "last_name": lastName,
        "phone": phone,
        "email": email,
        "remember_me": rememberMe,
      };

  factory AdminModel.empty() => AdminModel(
        profilePicLink: '',
        firstName: '',
        lastName: '',
        phone: '',
        email: '',
        rememberMe: false,
      );
}

In the above class there is an "empty()" method which has been created using AI. If there was a feature which created this method in one click, it would be very convenient.

Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant