feat: type schedule and auth models
This commit is contained in:
28
lib/models/auth_info.dart
Normal file
28
lib/models/auth_info.dart
Normal file
@@ -0,0 +1,28 @@
|
||||
class AuthInfo {
|
||||
final bool isAdmin;
|
||||
final String? name;
|
||||
|
||||
const AuthInfo({required this.isAdmin, this.name});
|
||||
|
||||
static AuthInfo fromApi(Object? data) {
|
||||
if (data is! Map) {
|
||||
throw const FormatException('auth/me должен быть объектом');
|
||||
}
|
||||
|
||||
final map = Map<String, dynamic>.from(data);
|
||||
return AuthInfo(
|
||||
isAdmin: _boolValue(map['is_admin']),
|
||||
name: map['name']?.toString(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
bool _boolValue(Object? value) {
|
||||
if (value is bool) return value;
|
||||
if (value is num) return value != 0;
|
||||
if (value is String) {
|
||||
final normalized = value.trim().toLowerCase();
|
||||
return normalized == 'true' || normalized == '1';
|
||||
}
|
||||
return false;
|
||||
}
|
||||
Reference in New Issue
Block a user