glideapps / quicktype

Generate types and converters from JSON, Schema, and GraphQL
https://app.quicktype.io
Apache License 2.0
11.76k stars 1.04k forks source link

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

Open jonathanjohn47 opened 1 month ago

jonathanjohn47 commented 1 month ago

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.