first app design
This commit is contained in:
@@ -0,0 +1,70 @@
|
||||
class Customer {
|
||||
final String id;
|
||||
final String firstName;
|
||||
final String lastName;
|
||||
final String? email;
|
||||
final String? phone;
|
||||
final String licenseStatus;
|
||||
final bool isFlagged;
|
||||
final String? flagReason;
|
||||
final DateTime? dateOfBirth;
|
||||
final String? nationality;
|
||||
final DateTime createdAt;
|
||||
|
||||
const Customer({
|
||||
required this.id,
|
||||
required this.firstName,
|
||||
required this.lastName,
|
||||
this.email,
|
||||
this.phone,
|
||||
required this.licenseStatus,
|
||||
required this.isFlagged,
|
||||
this.flagReason,
|
||||
this.dateOfBirth,
|
||||
this.nationality,
|
||||
required this.createdAt,
|
||||
});
|
||||
|
||||
String get fullName => '$firstName $lastName';
|
||||
|
||||
factory Customer.fromJson(Map<String, dynamic> json) => Customer(
|
||||
id: json['id'] as String,
|
||||
firstName: json['firstName'] as String,
|
||||
lastName: json['lastName'] as String,
|
||||
email: json['email'] as String?,
|
||||
phone: json['phone'] as String?,
|
||||
licenseStatus: json['licenseStatus'] as String? ?? 'PENDING',
|
||||
isFlagged: json['isFlagged'] as bool? ?? false,
|
||||
flagReason: json['flagReason'] as String?,
|
||||
dateOfBirth: json['dateOfBirth'] != null
|
||||
? DateTime.tryParse(json['dateOfBirth'] as String)
|
||||
: null,
|
||||
nationality: json['nationality'] as String?,
|
||||
createdAt: DateTime.parse(
|
||||
json['createdAt'] as String? ?? DateTime.now().toIso8601String()),
|
||||
);
|
||||
}
|
||||
|
||||
class CustomerListResponse {
|
||||
final List<Customer> data;
|
||||
final int total;
|
||||
final int page;
|
||||
final int pageSize;
|
||||
|
||||
const CustomerListResponse({
|
||||
required this.data,
|
||||
required this.total,
|
||||
required this.page,
|
||||
required this.pageSize,
|
||||
});
|
||||
|
||||
factory CustomerListResponse.fromJson(Map<String, dynamic> json) =>
|
||||
CustomerListResponse(
|
||||
data: (json['data'] as List<dynamic>)
|
||||
.map((e) => Customer.fromJson(e as Map<String, dynamic>))
|
||||
.toList(),
|
||||
total: json['total'] as int? ?? 0,
|
||||
page: json['page'] as int? ?? 1,
|
||||
pageSize: json['pageSize'] as int? ?? 20,
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user