Mimpungu
Dart Model Generator
Classe racine :
3 classes générées
JSON Input
user.dartAddressOrderUser
// Généré par Mimpungu Dart Model Generator
// ignore_for_file: invalid_annotation_target

class Address {
  final String street;
  final String city;
  final String zip;

  const Address({
    required this.street,
    required this.city,
    required this.zip,
  });

  factory Address.fromJson(Map<String, dynamic> json) => Address(
      street: json['street'] as String,
      city: json['city'] as String,
      zip: json['zip'] as String,
  );

  Map<String, dynamic> toJson() => {
      'street': street,
      'city': city,
      'zip': zip,
  };

  Address copyWith({
    String? street,
    String? city,
    String? zip,
  }) => Address(
      street: street ?? this.street,
      city: city ?? this.city,
      zip: zip ?? this.zip,
  );

  @override
  String toString() => 'Address(street: $street, city: $city, zip: $zip)';
}

class Order {
  final int id;
  final double amount;
  final String status;

  const Order({
    required this.id,
    required this.amount,
    required this.status,
  });

  factory Order.fromJson(Map<String, dynamic> json) => Order(
      id: (json['id'] as num).toInt(),
      amount: (json['amount'] as num).toDouble(),
      status: json['status'] as String,
  );

  Map<String, dynamic> toJson() => {
      'id': id,
      'amount': amount,
      'status': status,
  };

  Order copyWith({
    int? id,
    double? amount,
    String? status,
  }) => Order(
      id: id ?? this.id,
      amount: amount ?? this.amount,
      status: status ?? this.status,
  );

  @override
  String toString() => 'Order(id: $id, amount: $amount, status: $status)';
}

class User {
  final int id;
  final String name;
  final String email;
  final bool isActive;
  final double score;
  final DateTime createdAt;
  final Address address;
  final List<String> tags;
  final List<Order> orders;

  const User({
    required this.id,
    required this.name,
    required this.email,
    required this.isActive,
    required this.score,
    required this.createdAt,
    required this.address,
    required this.tags,
    required this.orders,
  });

  factory User.fromJson(Map<String, dynamic> json) => User(
      id: (json['id'] as num).toInt(),
      name: json['name'] as String,
      email: json['email'] as String,
      isActive: json['isActive'] as bool,
      score: (json['score'] as num).toDouble(),
      createdAt: DateTime.parse(json['createdAt'] as String),
      address: Address.fromJson(json['address'] as Map<String, dynamic>),
      tags: (json['tags'] as List<dynamic>?)?.map((e) => e.toString()).toList() ?? [],
      orders: (json['orders'] as List<dynamic>?)?.map((e) => Order.fromJson(e as Map<String, dynamic>)).toList() ?? [],
  );

  Map<String, dynamic> toJson() => {
      'id': id,
      'name': name,
      'email': email,
      'isActive': isActive,
      'score': score,
      'createdAt': createdAt?.toIso8601String(),
      'address': address?.toJson(),
      'tags': tags,
      'orders': orders?.map((e) => e.toJson()).toList(),
  };

  User copyWith({
    int? id,
    String? name,
    String? email,
    bool? isActive,
    double? score,
    DateTime? createdAt,
    Address? address,
    List<String> tags,
    List<Order> orders,
  }) => User(
      id: id ?? this.id,
      name: name ?? this.name,
      email: email ?? this.email,
      isActive: isActive ?? this.isActive,
      score: score ?? this.score,
      createdAt: createdAt ?? this.createdAt,
      address: address ?? this.address,
      tags: tags ?? this.tags,
      orders: orders ?? this.orders,
  );

  @override
  String toString() => 'User(id: $id, name: $name, email: $email, isActive: $isActive, score: $score, createdAt: $createdAt, address: $address, tags: $tags, orders: $orders)';
}
3 classesAddress (3 champs)Order (3 champs)User (9 champs)Dart · 100% local