-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New Account Details + MTR in Overview
Ability to set custom app image url by tapping the image updated pub packages const widgets to improve performance
- Loading branch information
1 parent
fc283b1
commit f89f1f0
Showing
31 changed files
with
851 additions
and
181 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import 'package:app/core/apis/general.api.dart'; | ||
import 'package:app/core/controllers/base.controller.dart'; | ||
import 'package:app/core/models/account.model.dart'; | ||
import 'package:app/core/models/app.model.dart'; | ||
import 'package:app/core/utils/logger.dart'; | ||
import 'package:flutter_easyrefresh/easy_refresh.dart'; | ||
import 'package:get/get.dart'; | ||
import 'package:intl/intl.dart'; | ||
|
||
final logger = initLogger("AccountController"); | ||
|
||
class AccountController extends BaseController { | ||
static AccountController get to => Get.find(); | ||
|
||
// VARIABLES | ||
final _api = Get.find<GeneralAPI>(); | ||
final refreshController = EasyRefreshController(); | ||
|
||
// PROPERTIES | ||
final account = Account().obs; | ||
|
||
// GETTERS | ||
List<App> get apps => account.value?.apps ?? []; | ||
|
||
String get accountId => account.value?.distinctId ?? ''; | ||
String get accountName => account.value?.name ?? ''; | ||
String get accountEmail => account.value?.email ?? ''; | ||
String get accountPlan => account.value?.currentPlan ?? ''; | ||
|
||
int get currentMtr => account.value?.billingInfo?.currentMtr ?? 0; | ||
int get mtrLimit => account.value?.billingInfo?.mtrLimit ?? 1; | ||
|
||
String get currentMtrFormatted => | ||
NumberFormat.simpleCurrency().format(currentMtr); | ||
|
||
String get mtrLimitFormatted => | ||
NumberFormat.simpleCurrency().format(mtrLimit); | ||
|
||
String get firstTransactionDate => account.value?.firstTransactionAt != null | ||
? DateFormat.yMMMMd().add_jm().format(account.value.firstTransactionAt) | ||
: 'none'; | ||
|
||
// INIT | ||
|
||
// FUNCTIONS | ||
Future<void> fetch() async { | ||
this.busyState(); | ||
account.value = Account(); | ||
final result = await _api.account(); | ||
|
||
result.fold( | ||
(error) => | ||
errorState(text: 'API Error: ${error.code}!\n${error.message}'), | ||
(data) { | ||
account.value = data; | ||
}, | ||
); | ||
|
||
this.idleState(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,185 @@ | ||
import 'app.model.dart'; | ||
|
||
class Account { | ||
Account({ | ||
this.apps, | ||
this.billingInfo, | ||
this.currentPlan, | ||
this.distinctId, | ||
this.email, | ||
this.exceededBasicLimit, | ||
this.firstTransactionAt, | ||
this.hasConfiguredEntitlements, | ||
this.hasConfiguredNewOfferings, | ||
this.hasMadeAnyLivePurchase, | ||
this.hasMadeAnyPurchase, | ||
this.intercomHash, | ||
this.isConnectedToStripe, | ||
this.name, | ||
this.subscriptions, | ||
}); | ||
|
||
final List<App> apps; | ||
final BillingInfo billingInfo; | ||
final String currentPlan; | ||
final String distinctId; | ||
final String email; | ||
final bool exceededBasicLimit; | ||
final DateTime firstTransactionAt; | ||
final bool hasConfiguredEntitlements; | ||
final bool hasConfiguredNewOfferings; | ||
final bool hasMadeAnyLivePurchase; | ||
final bool hasMadeAnyPurchase; | ||
final String intercomHash; | ||
final bool isConnectedToStripe; | ||
final String name; | ||
final Subscriptions subscriptions; | ||
|
||
factory Account.fromJson(Map<String, dynamic> json) => Account( | ||
apps: json["apps"] == null | ||
? null | ||
: List<App>.from(json["apps"].map((x) => App.fromJson(x))), | ||
billingInfo: json["billing_info"] == null | ||
? null | ||
: BillingInfo.fromJson(json["billing_info"]), | ||
currentPlan: json["current_plan"] == null ? null : json["current_plan"], | ||
distinctId: json["distinct_id"] == null ? null : json["distinct_id"], | ||
email: json["email"] == null ? null : json["email"], | ||
exceededBasicLimit: json["exceeded_basic_limit"] == null | ||
? null | ||
: json["exceeded_basic_limit"], | ||
firstTransactionAt: json["first_transaction_at"] == null | ||
? null | ||
: DateTime.parse(json["first_transaction_at"]), | ||
hasConfiguredEntitlements: json["has_configured_entitlements"] == null | ||
? null | ||
: json["has_configured_entitlements"], | ||
hasConfiguredNewOfferings: json["has_configured_new_offerings"] == null | ||
? null | ||
: json["has_configured_new_offerings"], | ||
hasMadeAnyLivePurchase: json["has_made_any_live_purchase"] == null | ||
? null | ||
: json["has_made_any_live_purchase"], | ||
hasMadeAnyPurchase: json["has_made_any_purchase"] == null | ||
? null | ||
: json["has_made_any_purchase"], | ||
intercomHash: | ||
json["intercom_hash"] == null ? null : json["intercom_hash"], | ||
isConnectedToStripe: json["is_connected_to_stripe"] == null | ||
? null | ||
: json["is_connected_to_stripe"], | ||
name: json["name"] == null ? null : json["name"], | ||
subscriptions: json["subscriptions"] == null | ||
? null | ||
: Subscriptions.fromJson(json["subscriptions"]), | ||
); | ||
|
||
Map<String, dynamic> toJson() => { | ||
"apps": apps == null | ||
? null | ||
: List<dynamic>.from(apps.map((x) => x.toJson())), | ||
"billing_info": billingInfo == null ? null : billingInfo.toJson(), | ||
"current_plan": currentPlan == null ? null : currentPlan, | ||
"distinct_id": distinctId == null ? null : distinctId, | ||
"email": email == null ? null : email, | ||
"exceeded_basic_limit": | ||
exceededBasicLimit == null ? null : exceededBasicLimit, | ||
"first_transaction_at": firstTransactionAt == null | ||
? null | ||
: firstTransactionAt.toIso8601String(), | ||
"has_configured_entitlements": hasConfiguredEntitlements == null | ||
? null | ||
: hasConfiguredEntitlements, | ||
"has_configured_new_offerings": hasConfiguredNewOfferings == null | ||
? null | ||
: hasConfiguredNewOfferings, | ||
"has_made_any_live_purchase": | ||
hasMadeAnyLivePurchase == null ? null : hasMadeAnyLivePurchase, | ||
"has_made_any_purchase": | ||
hasMadeAnyPurchase == null ? null : hasMadeAnyPurchase, | ||
"intercom_hash": intercomHash == null ? null : intercomHash, | ||
"is_connected_to_stripe": | ||
isConnectedToStripe == null ? null : isConnectedToStripe, | ||
"name": name == null ? null : name, | ||
"subscriptions": subscriptions == null ? null : subscriptions.toJson(), | ||
}; | ||
} | ||
|
||
class BillingInfo { | ||
BillingInfo({ | ||
this.currentMtr, | ||
this.mtrLimit, | ||
this.paymentCard, | ||
this.periodEnd, | ||
this.periodStart, | ||
}); | ||
|
||
final int currentMtr; | ||
final int mtrLimit; | ||
final PaymentCard paymentCard; | ||
final DateTime periodEnd; | ||
final DateTime periodStart; | ||
|
||
factory BillingInfo.fromJson(Map<String, dynamic> json) => BillingInfo( | ||
currentMtr: json["current_mtr"] == null ? null : json["current_mtr"], | ||
mtrLimit: json["mtr_limit"] == null ? null : json["mtr_limit"], | ||
paymentCard: json["payment_card"] == null | ||
? null | ||
: PaymentCard.fromJson(json["payment_card"]), | ||
periodEnd: json["period_end"] == null | ||
? null | ||
: DateTime.parse(json["period_end"]), | ||
periodStart: json["period_start"] == null | ||
? null | ||
: DateTime.parse(json["period_start"]), | ||
); | ||
|
||
Map<String, dynamic> toJson() => { | ||
"current_mtr": currentMtr == null ? null : currentMtr, | ||
"mtr_limit": mtrLimit == null ? null : mtrLimit, | ||
"payment_card": paymentCard == null ? null : paymentCard.toJson(), | ||
"period_end": periodEnd == null ? null : periodEnd.toIso8601String(), | ||
"period_start": | ||
periodStart == null ? null : periodStart.toIso8601String(), | ||
}; | ||
} | ||
|
||
class PaymentCard { | ||
PaymentCard({ | ||
this.brand, | ||
this.country, | ||
this.expirationMonth, | ||
this.expirationYear, | ||
this.lastDigits, | ||
}); | ||
|
||
final dynamic brand; | ||
final dynamic country; | ||
final dynamic expirationMonth; | ||
final dynamic expirationYear; | ||
final dynamic lastDigits; | ||
|
||
factory PaymentCard.fromJson(Map<String, dynamic> json) => PaymentCard( | ||
brand: json["brand"], | ||
country: json["country"], | ||
expirationMonth: json["expiration_month"], | ||
expirationYear: json["expiration_year"], | ||
lastDigits: json["last_digits"], | ||
); | ||
|
||
Map<String, dynamic> toJson() => { | ||
"brand": brand, | ||
"country": country, | ||
"expiration_month": expirationMonth, | ||
"expiration_year": expirationYear, | ||
"last_digits": lastDigits, | ||
}; | ||
} | ||
|
||
class Subscriptions { | ||
Subscriptions(); | ||
|
||
factory Subscriptions.fromJson(Map<String, dynamic> json) => Subscriptions(); | ||
|
||
Map<String, dynamic> toJson() => {}; | ||
} |
Oops, something went wrong.