78 lines
2.5 KiB
Dart
78 lines
2.5 KiB
Dart
import 'dart:developer';
|
|
|
|
import 'package:didvan/constants/assets.dart';
|
|
import 'package:didvan/models/enums.dart';
|
|
import 'package:didvan/models/new_statistic/new_statistics_model.dart';
|
|
import 'package:didvan/providers/core.dart';
|
|
import 'package:didvan/services/network/request.dart';
|
|
import 'package:didvan/services/network/request_helper.dart';
|
|
import 'package:didvan/views/home/new_statistic/widgets/statistic_cat.dart';
|
|
|
|
class NewStatisticState extends CoreProvier {
|
|
final List<CategoryList> contents = [];
|
|
|
|
List<StatMenuItemType> statCat = [];
|
|
|
|
Future<void> getStatistic() async {
|
|
appState = AppState.busy;
|
|
final RequestService service = RequestService(
|
|
RequestHelper.newStatisticOverViw(),
|
|
);
|
|
await service.httpGet();
|
|
if (service.isSuccess) {
|
|
final res = NewStatisticModel.fromJson(service.result);
|
|
|
|
contents.clear();
|
|
|
|
for (var element in res.lists) {
|
|
contents.add(element);
|
|
}
|
|
|
|
appState = AppState.idle;
|
|
return;
|
|
}
|
|
appState = AppState.failed;
|
|
}
|
|
|
|
void init() {
|
|
statCat = [
|
|
StatMenuItemType(
|
|
label: "بازار ارز و طلا", asset: Assets.currencyGoldStatCat, id: 1),
|
|
StatMenuItemType(
|
|
label: "ارزهای دیجیتال", asset: Assets.cryptoStatCat, id: 2),
|
|
StatMenuItemType(label: "فلزات پایه", asset: Assets.metalStatCat, id: 3),
|
|
StatMenuItemType(
|
|
label: "کامودیتیها", asset: Assets.commodityStatCat, id: 4),
|
|
StatMenuItemType(label: "صنعت فولاد", asset: Assets.steelStatCat, id: 5),
|
|
StatMenuItemType(
|
|
label: "بازار سرمایه", asset: Assets.stockStatCat, id: 6),
|
|
];
|
|
Future.delayed(Duration.zero, () {
|
|
getStatistic();
|
|
});
|
|
}
|
|
|
|
void refresh() {
|
|
statCat = [
|
|
StatMenuItemType(
|
|
label: "بازار ارز و طلا", asset: Assets.currencyGoldStatCat, id: 1),
|
|
StatMenuItemType(
|
|
label: "ارزهای دیجیتال", asset: Assets.cryptoStatCat, id: 2),
|
|
StatMenuItemType(label: "فلزات پایه", asset: Assets.metalStatCat, id: 3),
|
|
StatMenuItemType(
|
|
label: "کامودیتیها", asset: Assets.commodityStatCat, id: 4),
|
|
StatMenuItemType(label: "صنعت فولاد", asset: Assets.steelStatCat, id: 5),
|
|
StatMenuItemType(
|
|
label: "بازار سرمایه", asset: Assets.stockStatCat, id: 6),
|
|
];
|
|
update();
|
|
}
|
|
|
|
void resetState() {
|
|
contents.clear();
|
|
notifyListeners();
|
|
getStatistic();
|
|
log("Blakh");
|
|
}
|
|
}
|