MBUser.fromDictionary constructor

MBUser.fromDictionary(
  1. Map<String, dynamic> dictionary
)

Initializes a user from the dictionary returned by the api

Implementation

factory MBUser.fromDictionary(Map<String, dynamic> dictionary) {
  int id = dictionary['id'] as int;
  String? name;
  if (dictionary['name'] is String) {
    name = dictionary['name'] as String;
  }
  String? surname;
  if (dictionary['surname'] is String) {
    surname = dictionary['surname'] as String;
  }
  String email = dictionary['email'] as String;
  String? phone;
  if (dictionary['phone'] is String) {
    phone = dictionary['phone'] as String;
  }
  String? imageUrl;
  if (dictionary['image'] is String) {
    imageUrl = dictionary['image'] as String;
  }

  List<MBUserContractStatus>? contracts;
  if (dictionary['contracts'] != null) {
    List<Map<String, dynamic>> contractsArray =
        List.from(dictionary['contracts'] as List);
    contracts = contractsArray
        .map((d) => MBUserContractStatus.fromDictionary(d))
        .toList();
  }

  MBUserAuthMode authMode =
      _authModeFromString(dictionary["auth_mode"] as String);

  Map<String, dynamic>? data;
  if (dictionary['data'] != null) {
    if (dictionary['data'] is Map<String, dynamic>) {
      data = dictionary['data'] as Map<String, dynamic>;
    }
  }

  return MBUser(
    id: id,
    name: name,
    surname: surname,
    email: email,
    phone: phone,
    imageUrl: imageUrl,
    data: data,
    contracts: contracts,
    authMode: authMode,
  );
}