Files
Finlytic/FinlyticApp/lib/features/auth/models/user_model.dart
T

44 lines
1.1 KiB
Dart

import 'package:equatable/equatable.dart';
/// UserModel representing authenticated user session data.
class UserModel extends Equatable {
final String userId;
final String email;
final String fullName;
final String role;
final String? token;
const UserModel({
required this.userId,
required this.email,
required this.fullName,
required this.role,
this.token,
});
bool get isAdmin => role.toLowerCase() == 'admin';
factory UserModel.fromJson(Map<String, dynamic> json, {String? token}) {
return UserModel(
userId: json['userId']?.toString() ?? json['id']?.toString() ?? '',
email: json['email']?.toString() ?? '',
fullName: json['fullName']?.toString() ?? json['name']?.toString() ?? '',
role: json['role']?.toString() ?? 'User',
token: token ?? json['token']?.toString(),
);
}
Map<String, dynamic> toJson() {
return {
'userId': userId,
'email': email,
'fullName': fullName,
'role': role,
'token': token,
};
}
@override
List<Object?> get props => [userId, email, fullName, role, token];
}