| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121 |
- // ignore_for_file: constant_identifier_names, non_constant_identifier_names
- import 'package:flutter/foundation.dart';
- import 'package:flutter/material.dart';
- import 'package:gozap_package/components/apiservices.dart';
- import 'package:gozap_package/models/swap/swap_count_model.dart';
- import 'package:gozap_package/models/swap/swap_history_model.dart';
- import 'package:gozap_package/models/swap/swap_model.dart';
- import 'package:gozap_package/models/user/user_model.dart';
- import 'package:provider/provider.dart';
- enum DashboardModelStatus {
- Ended,
- Loading,
- Error,
- }
- class DashboardModel extends ChangeNotifier {
- late DashboardModelStatus _status;
- late String _errorCode;
- late String _errorMessage;
- late SwapModule? _swapModule;
- String get errorCode => _errorCode;
- String get errorMessage => _errorMessage;
- DashboardModelStatus get status => _status;
- SwapModule? get swapModule => _swapModule;
- DashboardModel();
- DashboardModel.instance(BuildContext context) {
- // ignore: todo
- //TODO Add code here
- getter(context);
- }
- Future<void> getter(BuildContext context) async {
- _status = DashboardModelStatus.Loading;
- notifyListeners();
- try {
- String UserID = Provider.of<userChangeNotifier>(context, listen: false)
- .user!
- .UserID
- .toString();
- var mapData = await APIService(context).postData(
- "User/",
- {"UserID": UserID},
- false);
- if (mapData != null) {
- UserModule userModule = UserModule.fromJson(mapData["UserData"]);
- SwapCountModule remaingSwapModule =
- SwapCountModule.fromJson(mapData["SwapData"]["RemainingData"]);
- SwapCountModule referSwapModule =
- SwapCountModule.fromJson(mapData["SwapData"]["ReferData"]);
- SwapCountModule rechargeSwapModule =
- SwapCountModule.fromJson(mapData["SwapData"]["RechargeData"]);
- SwapCountModule freeSwapModule =
- SwapCountModule.fromJson(mapData["SwapData"]["FreeData"]);
- List<SwapHistoryModule> swapHistoryList = [];
- for (var element in mapData["SwapData"]["HistoryData"]["History"]) {
- swapHistoryList.add(SwapHistoryModule.fromJson(element));
- }
- SwapHistoryMetaModule swapHistoryMetaModule = SwapHistoryMetaModule(
- TotalCount: mapData["SwapData"]["HistoryData"]["TotalCount"],
- FreeSwapCount: mapData["SwapData"]["HistoryData"]["FreeSwapCount"],
- PaidSwapCount: mapData["SwapData"]["HistoryData"]["PaidSwapCount"],
- SwapHistoryList: swapHistoryList);
- _swapModule = SwapModule(
- User: userModule,
- RemaingSwap: remaingSwapModule,
- ReferSwap: referSwapModule,
- RechargeSwap: rechargeSwapModule,
- FreeSwap: freeSwapModule,
- SwapHistoryMeta: swapHistoryMetaModule);
- }
- } catch (e) {
- _swapModule = null;
- if (kDebugMode) {
- print(e);
- }
- }
- _status = DashboardModelStatus.Ended;
- notifyListeners();
- }
- void setter() {
- _status = DashboardModelStatus.Loading;
- notifyListeners();
- // ignore: todo
- //TODO Add code here
- _status = DashboardModelStatus.Ended;
- notifyListeners();
- }
- void update() {
- _status = DashboardModelStatus.Loading;
- notifyListeners();
- // ignore: todo
- //TODO Add code here
- _status = DashboardModelStatus.Ended;
- notifyListeners();
- }
- void remove() {
- _status = DashboardModelStatus.Loading;
- notifyListeners();
- // ignore: todo
- //TODO Add code here
- _status = DashboardModelStatus.Ended;
- notifyListeners();
- }
- }
|