Refactor code structure for improved readability and maintainability
Co-authored-by: Copilot <copilot@github.com>
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
class UserProfile {
|
||||
final int id;
|
||||
final String username;
|
||||
final String email;
|
||||
final String? firstName;
|
||||
final String? lastName;
|
||||
final String role;
|
||||
|
||||
const UserProfile({
|
||||
required this.id,
|
||||
required this.username,
|
||||
required this.email,
|
||||
this.firstName,
|
||||
this.lastName,
|
||||
required this.role,
|
||||
});
|
||||
|
||||
factory UserProfile.fromJson(Map<String, dynamic> json) => UserProfile(
|
||||
id: json['id'] as int,
|
||||
username: json['username'] as String,
|
||||
email: json['email'] as String? ?? '',
|
||||
firstName: json['firstName'] as String?,
|
||||
lastName: json['lastName'] as String?,
|
||||
role: json['role'] as String? ?? 'user',
|
||||
);
|
||||
|
||||
bool get isAdmin => role == 'admin';
|
||||
|
||||
UserProfile copyWith({
|
||||
String? email,
|
||||
String? firstName,
|
||||
String? lastName,
|
||||
}) =>
|
||||
UserProfile(
|
||||
id: id,
|
||||
username: username,
|
||||
email: email ?? this.email,
|
||||
firstName: firstName ?? this.firstName,
|
||||
lastName: lastName ?? this.lastName,
|
||||
role: role,
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user