class model

mail@pastecode.io avatar
unknown
dart
7 months ago
2.4 kB
4
Indexable
Never
class WorkerModel {
  String image;
  String name;
  String location;
  int experience;
  double hourRate;
  double rating;
  double ratingCount;
  String status;
  String about;
  List<String> strengths;
  String category;
  String $id;
  String $createdAt;
  String $updateAt;

  WorkerModel({
    required this.image,
    required this.name,
    required this.location,
    required this.experience,
    required this.hourRate,
    required this.rating,
    required this.ratingCount,
    required this.status,
    required this.about,
    required this.strengths,
    required this.category,
    required this.$id,
    required this.$createdAt,
    required this.$updateAt,
  });

  factory WorkerModel.fromJson(Map<String, dynamic> json) => WorkerModel(
        image: json["image"] ?? "",
        name: json["name"] ?? "",
        location: json["location"] ?? "",
        experience:
            json["experience"] == null ? 0 : int.parse(json["experience"]),
        // hourRate: json["hour_rate"]?.toDouble() ?? 0.0,
        // rating: json["rating"]?.toDouble() ?? 0.0,
        // ratingCount: json["rating_count"]?.toDouble() ?? 0.0,
        hourRate:
            json["hour_rate"] == null ? 0.0 : double.parse(json["hour_rate"]),
        rating: json["rating"] == null ? 0.0 : double.parse(json["rating"]),
        ratingCount: json["rating_count"] == null
            ? 0.0
            : double.parse(json["rating_count"]),
        status: json["status"] ?? "",
        about: json["about"] ?? "",
        strengths: json["strengths"] == null
            ? []
            : List<String>.from(json["strengths"].map((x) => x)),
        category: json["category"] ?? "",
        $id: json["\$id"],
        $createdAt: json["\$createdAt"],
        $updateAt: json["\$updateAt"],
      );

  Map<String, dynamic> toJson(WorkerModel workerModel) => {
        "image": image,
        "name": name,
        "location": location,
        "experience": experience,
        "hour_rate": hourRate,
        "rating": rating,
        "rating_count": ratingCount,
        "status": status,
        "about": about,
        "strengths": List<dynamic>.from(strengths.map((x) => x)),
        "category": category,
        "\$id": $id,
        "\$createdAt": $createdAt,
        "\$updateAt": $updateAt,
      };
}
Leave a Comment