Co-authored-by: MENDOZA BALLARDO GAEL RICARDO <gael-meb123@users.noreply.github.com>
Co-authored-by: Azareth-Tr <Azareth-Tr@users.noreply.githu b.com> correcion de errores en llenado de tablas, primeras vistas frontend
This commit is contained in:
50
recolecta_app/lib/core/models/user.dart
Normal file
50
recolecta_app/lib/core/models/user.dart
Normal file
@@ -0,0 +1,50 @@
|
||||
class User {
|
||||
const User({
|
||||
required this.id,
|
||||
this.email,
|
||||
this.phone,
|
||||
required this.role,
|
||||
this.routeId,
|
||||
});
|
||||
|
||||
final String id;
|
||||
final String? email;
|
||||
final String? phone;
|
||||
final String role;
|
||||
final String? routeId;
|
||||
|
||||
factory User.fromJson(Map<String, dynamic> json) {
|
||||
return User(
|
||||
id:
|
||||
_pickString(<dynamic>[json['id'], json['user_id'], json['userId']]) ??
|
||||
'',
|
||||
email: _pickString(<dynamic>[json['email'], json['mail']]),
|
||||
phone: _pickString(<dynamic>[json['phone'], json['telefono']]),
|
||||
role: _pickString(<dynamic>[json['role'], json['rol']]) ?? 'citizen',
|
||||
routeId: _pickString(<dynamic>[json['routeId'], json['route_id']]),
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
return <String, dynamic>{
|
||||
'id': id,
|
||||
'email': email,
|
||||
'phone': phone,
|
||||
'role': role,
|
||||
'routeId': routeId,
|
||||
};
|
||||
}
|
||||
|
||||
static String? _pickString(Iterable<dynamic> candidates) {
|
||||
for (final candidate in candidates) {
|
||||
if (candidate is String && candidate.isNotEmpty) {
|
||||
return candidate;
|
||||
}
|
||||
if (candidate != null && candidate.toString().isNotEmpty) {
|
||||
return candidate.toString();
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user