Skip to content

Instantly share code, notes, and snippets.

@M001T
Created November 29, 2021 13:50
Show Gist options
  • Save M001T/be30172d53247d52aeaffca299196778 to your computer and use it in GitHub Desktop.
Save M001T/be30172d53247d52aeaffca299196778 to your computer and use it in GitHub Desktop.
user_model
import 'package:flutter_modular/flutter_modular.dart';
import 'package:pandapay_flutter/app/core/utils/constants/storage_keys.dart';
import 'package:pandapay_flutter/app/infrastructure/data/datasources/local/secure_local_datasource.dart';
import 'package:pandapay_flutter/app/models/user_api_model/crypto_address_model/crypto_address_model.dart';
import '../../features/auth/data/models/user/child_models/kyc_model.dart';
import '../../features/auth/data/models/user/child_models/missing_data_model.dart';
import 'banners_model/banner_model.dart';
import 'services_model/services_model.dart';
import 'user_model/user_model.dart';
class UserApiModel {
final secureLocalDatasource = Modular.get<SecureLocalDataSource>();
int code;
String message;
String token;
UserModell user;
KycModel kyc;
MissingDataModel missingData;
List<ServicesModel> servicesList;
List<CryptoAddressModel> cryptoAddresses;
List<BannersModel> bannersList;
UserApiModel(
{this.code, this.message, this.user, this.token, this.servicesList, this.bannersList});
UserApiModel fromJson(Map<String, dynamic> json) {
code = json['code'];
message = json['message'];
/* print('O QUE TA CHEGANDO NO USER MODEL ANTIGO');
print('\n${const JsonEncoder.withIndent(' ').convert(json)} \n');
print('O QUE TA CHEGANDO NO USER MODEL ANTIGO'); */
if (json['data'] != null) {
user = UserModell().fromJson(json['data']['user']);
if (json['data']['token'] != null) token = json['data']['token'];
servicesList = <ServicesModel>[];
json['data']['services'].forEach(
(service) => servicesList.add(ServicesModel.fromJson(service)));
if (json['data']['token'] != null) token = json['data']['token'];
bannersList = <BannersModel>[];
json['data']['banners'].forEach(
(banners) => bannersList.add(BannersModel.fromJson(banners)));
if (json['data']['kyc'] != null)
kyc = KycModel().fromJson(json['data']['kyc']);
if (json['data']['missingData'] != null)
missingData = MissingDataModel().fromJson(json['data']['missingData']);
cryptoAddresses = [];
if (json['data']['cryptoAddresses'] != null)
json['data']['cryptoAddresses'].forEach((address) =>
cryptoAddresses.add(CryptoAddressModel.fromJson(address)));
}
print("user_api_model: ${bannersList}");
return this;
}
Map<String, dynamic> toJson() {
final Map<String, dynamic> data = Map<String, dynamic>();
data['code'] = this.code;
data['message'] = this.message;
if (user != null) {
data['user'] = this.user.toJson();
data['token'] = this.token;
data['services'] =
this.servicesList.map((service) => service.toJson()).toList();
data['banners'] =
this.bannersList.map((banners) => banners.toJson()).toList();
}
return data;
}
get success {
return user != null && token != null && servicesList != null && bannersList != null;
}
@override
String toString() {
return "$code - $message - $user - $servicesList - $bannersList";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment