292 lines
10 KiB
Dart
292 lines
10 KiB
Dart
import 'dart:convert';
|
|
|
|
import 'package:handyman_provider_flutter/models/provider_subscription_model.dart';
|
|
import 'package:nb_utils/nb_utils.dart';
|
|
|
|
class UserData {
|
|
int? id;
|
|
String? uid;
|
|
String? username;
|
|
String? lastName;
|
|
String? email;
|
|
String? firstName;
|
|
String? emailVerifiedAt;
|
|
String? userType;
|
|
String? contactNumber;
|
|
int? countryId;
|
|
int? stateId;
|
|
int? cityId;
|
|
int? religionId;
|
|
String? address;
|
|
int? providerId;
|
|
String? playerId;
|
|
int? status;
|
|
int? providertypeId;
|
|
int? isFeatured;
|
|
String? displayName;
|
|
String? timeZone;
|
|
String? lastNotificationSeen;
|
|
String? createdAt;
|
|
String? updatedAt;
|
|
String? deletedAt;
|
|
String? apiToken;
|
|
String? profileImage;
|
|
String? description;
|
|
String? knownLanguages;
|
|
String? whyChooseMe;
|
|
String? skills;
|
|
int? serviceAddressId;
|
|
num? handymanRating;
|
|
int? isSubscribe;
|
|
String? designation;
|
|
String? password;
|
|
String? cityName;
|
|
num? providerServiceRating;
|
|
String? providerType;
|
|
bool? isHandymanAvailable;
|
|
String? loginType;
|
|
String? handymanType;
|
|
num? slotsForAllServices;
|
|
int? isOnline;
|
|
List<String>? userRole;
|
|
ProviderSubscriptionModel? subscription;
|
|
|
|
int? isEmailVerified;
|
|
|
|
//Local
|
|
bool isActive = false;
|
|
|
|
bool get isUserActive => status == 0;
|
|
|
|
/// This is to check if the provider's all services have time slot or not.
|
|
bool get isSlotsForAllServices => slotsForAllServices == 1;
|
|
|
|
List<String> get knownLanguagesArray => buildKnownLanguages();
|
|
|
|
List<String> get skillsArray => buildSkills();
|
|
|
|
List<String> buildKnownLanguages() {
|
|
List<String> array = [];
|
|
String tempLanguages = knownLanguages.validate();
|
|
if (tempLanguages.isNotEmpty && tempLanguages.isJson()) {
|
|
Iterable it1 = jsonDecode(knownLanguages.validate());
|
|
array.addAll(it1.map((e) => e.toString()).toList());
|
|
}
|
|
|
|
return array;
|
|
}
|
|
|
|
List<String> buildSkills() {
|
|
List<String> array = [];
|
|
String tempSkills = skills.validate();
|
|
if (tempSkills.isNotEmpty && tempSkills.isJson()) {
|
|
Iterable it2 = jsonDecode(skills.validate());
|
|
array.addAll(it2.map((e) => e.toString()).toList());
|
|
}
|
|
|
|
return array;
|
|
}
|
|
|
|
WhyChooseMe get whyChooseMeObj => buildWhyChooseMe();
|
|
|
|
WhyChooseMe buildWhyChooseMe() {
|
|
WhyChooseMe obj = WhyChooseMe();
|
|
String tempWhyChooseMe = whyChooseMe.validate();
|
|
if (tempWhyChooseMe.isNotEmpty && tempWhyChooseMe.isJson()) {
|
|
obj = WhyChooseMe.fromJson(jsonDecode(tempWhyChooseMe));
|
|
}
|
|
|
|
return obj;
|
|
}
|
|
|
|
UserData({
|
|
this.id,
|
|
this.username,
|
|
this.firstName,
|
|
this.lastName,
|
|
this.email,
|
|
this.emailVerifiedAt,
|
|
this.userType,
|
|
this.contactNumber,
|
|
this.countryId,
|
|
this.religionId,
|
|
this.providerServiceRating,
|
|
this.stateId,
|
|
this.cityId,
|
|
this.address,
|
|
this.providerId,
|
|
this.playerId,
|
|
this.slotsForAllServices,
|
|
this.status,
|
|
this.providertypeId,
|
|
this.isFeatured,
|
|
this.displayName,
|
|
this.timeZone,
|
|
this.lastNotificationSeen,
|
|
this.createdAt,
|
|
this.updatedAt,
|
|
this.deletedAt,
|
|
this.userRole,
|
|
this.apiToken,
|
|
this.profileImage,
|
|
this.description,
|
|
this.knownLanguages,
|
|
this.whyChooseMe,
|
|
this.skills,
|
|
this.serviceAddressId,
|
|
this.handymanRating,
|
|
this.subscription,
|
|
this.isSubscribe,
|
|
this.uid,
|
|
this.designation,
|
|
this.cityName,
|
|
this.providerType,
|
|
this.handymanType,
|
|
this.isHandymanAvailable,
|
|
this.loginType,
|
|
this.isEmailVerified,
|
|
});
|
|
|
|
UserData.fromJson(Map<String, dynamic> json) {
|
|
id = json['id'].toString().toInt();
|
|
username = json['username'];
|
|
firstName = json['first_name'];
|
|
lastName = json['last_name'];
|
|
religionId = json['religion_id'] != null ? json['religion_id'].toString().toInt() : null;
|
|
slotsForAllServices = json['slots_for_all_services'] != null ? json['slots_for_all_services'].toString().toInt() : 0;
|
|
email = json['email'];
|
|
emailVerifiedAt = json['email_verified_at'];
|
|
providerServiceRating = json['providers_service_rating'];
|
|
isOnline = json['isOnline'];
|
|
userType = json['user_type'];
|
|
contactNumber = json['contact_number'];
|
|
countryId = json['country_id'] != null ? json['country_id'].toString().toInt() : null;
|
|
stateId = json['state_id'] != null ? json['state_id'].toString().toInt() : null;
|
|
cityId = json['city_id'] != null ? json['city_id'].toString().toInt() : null;
|
|
address = json['address'];
|
|
providerId = json['provider_id'] != null ? json['provider_id'].toString().toInt() : null;
|
|
playerId = json['player_id'];
|
|
status = json['status'] != null ? json['status'].toString().toInt() : null;
|
|
isActive = status == 1;
|
|
serviceAddressId = json['service_address_id'] != null ? json['service_address_id'].toString().toInt() : null;
|
|
handymanRating = json['handyman_rating'];
|
|
|
|
displayName = json['display_name'];
|
|
timeZone = json['time_zone'];
|
|
lastNotificationSeen = json['last_notification_seen'];
|
|
createdAt = json['created_at'];
|
|
updatedAt = json['updated_at'];
|
|
deletedAt = json['deleted_at'];
|
|
apiToken = json['api_token'];
|
|
profileImage = json['profile_image'];
|
|
description = json['description'];
|
|
knownLanguages = json['known_languages'];
|
|
whyChooseMe = json['why_choose_me'];
|
|
skills = json['skills'];
|
|
uid = json['uid'];
|
|
subscription = json['subscription'] != null ? ProviderSubscriptionModel.fromJson(json['subscription']) : null;
|
|
isSubscribe = json['is_subscribe'] != null ? json['is_subscribe'].toString().toInt() : null;
|
|
designation = json['designation'];
|
|
cityName = json['city_name'];
|
|
providerType = json['providertype'];
|
|
handymanType = json['handymantype'];
|
|
if (json.containsKey('isHandymanAvailable')) {
|
|
isHandymanAvailable = json['isHandymanAvailable'].toString() == '1' || json['isHandymanAvailable'] == true;
|
|
}
|
|
loginType = json['login_type'];
|
|
isEmailVerified = json['is_email_verified'] != null ? json['is_email_verified'].toString().toInt() : null;
|
|
}
|
|
|
|
Map<String, dynamic> toJson() {
|
|
final Map<String, dynamic> data = new Map<String, dynamic>();
|
|
if (this.id != null) data['id'] = this.id;
|
|
if (this.slotsForAllServices != null) data['slots_for_all_services'] = this.slotsForAllServices;
|
|
if (this.username != null) data['username'] = this.username;
|
|
if (this.firstName != null) data['first_name'] = this.firstName;
|
|
if (this.lastName != null) data['last_name'] = this.lastName;
|
|
if (this.email != null) data['email'] = this.email;
|
|
if (this.providerServiceRating != null) data['providers_service_rating'] = this.providerServiceRating;
|
|
if (this.serviceAddressId != null) data['service_address_id'] = this.serviceAddressId;
|
|
if (this.handymanRating != null) data['handyman_rating'] = this.handymanRating;
|
|
if (this.emailVerifiedAt != null) data['email_verified_at'] = this.emailVerifiedAt;
|
|
if (this.userType != null) data['user_type'] = this.userType;
|
|
if (this.contactNumber != null) data['contact_number'] = this.contactNumber;
|
|
if (this.countryId != null) data['country_id'] = this.countryId;
|
|
if (this.isOnline != null) data['isOnline'] = this.isOnline;
|
|
if (this.handymanType != null) data['handymantype'] = this.handymanType;
|
|
if (this.stateId != null) data['state_id'] = this.stateId;
|
|
if (this.cityId != null) data['city_id'] = this.cityId;
|
|
if (this.religionId != null) data['religion_id'] = this.religionId;
|
|
if (this.address != null) data['address'] = this.address;
|
|
if (this.providerId != null) data['provider_id'] = this.providerId;
|
|
if (this.playerId != null) data['player_id'] = this.playerId;
|
|
if (this.status != null) data['status'] = this.status;
|
|
if (this.providertypeId != null) data['providertype_id'] = this.providertypeId;
|
|
|
|
if (this.displayName != null) data['display_name'] = this.displayName;
|
|
if (this.timeZone != null) data['time_zone'] = this.timeZone;
|
|
if (this.lastNotificationSeen != null) data['last_notification_seen'] = this.lastNotificationSeen;
|
|
if (this.createdAt != null) data['created_at'] = this.createdAt;
|
|
if (this.updatedAt != null) data['updated_at'] = this.updatedAt;
|
|
if (this.deletedAt != null) data['deleted_at'] = this.deletedAt;
|
|
if (this.userRole != null) data['user_role'] = this.userRole;
|
|
if (this.apiToken != null) data['api_token'] = this.apiToken;
|
|
if (this.profileImage != null) data['profile_image'] = this.profileImage;
|
|
if (this.description != null) data['description'] = this.description;
|
|
if (this.knownLanguages != null) data['known_languages'] = this.knownLanguages;
|
|
if (this.whyChooseMe != null) data['why_choose_me'] = this.whyChooseMe;
|
|
if (this.skills != null) data['skills'] = this.skills;
|
|
if (this.uid != null) data['uid'] = this.uid;
|
|
if (this.isSubscribe != null) data['is_subscribe'] = this.isSubscribe;
|
|
if (this.cityName != null) data['city_name'] = this.cityName;
|
|
if (this.providerType != null) data['providertype'] = this.providerType;
|
|
if (this.isHandymanAvailable != null) data['isHandymanAvailable'] = this.isHandymanAvailable;
|
|
if (this.loginType != null) data['login_type'] = this.loginType;
|
|
if (this.isEmailVerified != null) data['is_email_verified'] = this.isEmailVerified;
|
|
|
|
if (this.subscription != null) {
|
|
data['subscription'] = this.subscription!.toJson();
|
|
}
|
|
if (this.designation != null) data['designation'] = this.designation;
|
|
return data;
|
|
}
|
|
|
|
Map<String, dynamic> toFirebaseJson() {
|
|
final Map<String, dynamic> data = new Map<String, dynamic>();
|
|
if (this.id != null) data['id'] = this.id;
|
|
if (this.uid != null) data['uid'] = this.uid;
|
|
if (this.firstName != null) data['first_name'] = this.firstName;
|
|
if (this.lastName != null) data['last_name'] = this.lastName;
|
|
if (this.email != null) data['email'] = this.email;
|
|
if (this.profileImage != null) data['profile_image'] = this.profileImage;
|
|
if (this.isOnline != null) data['isOnline'] = this.isOnline;
|
|
if (this.updatedAt != null) data['updated_at'] = this.updatedAt;
|
|
if (this.createdAt != null) data['created_at'] = this.createdAt;
|
|
return data;
|
|
}
|
|
}
|
|
|
|
class WhyChooseMe {
|
|
String title;
|
|
List<String> reason;
|
|
|
|
WhyChooseMe({
|
|
this.title = "",
|
|
this.reason = const <String>[],
|
|
});
|
|
|
|
factory WhyChooseMe.fromJson(Map<String, dynamic> json) {
|
|
return WhyChooseMe(
|
|
title: json['why_choose_me_title'] is String ? json['why_choose_me_title'] : "",
|
|
reason: json['why_choose_me_reason'] is List ? List<String>.from(json['why_choose_me_reason'].map((x) => x)) : [],
|
|
);
|
|
}
|
|
|
|
Map<String, dynamic> toJson() {
|
|
return {
|
|
'why_choose_me_title': title,
|
|
'why_choose_me_reason': reason.map((e) => e).toList(),
|
|
};
|
|
}
|
|
}
|