96 lines
2.8 KiB
Dart
96 lines
2.8 KiB
Dart
|
|
import 'package:didvan/models/enums.dart';
|
|
import 'package:didvan/models/new_statistic/exchange_model.dart';
|
|
import 'package:didvan/models/new_statistic/metal_model.dart';
|
|
import 'package:didvan/models/new_statistic/total_type3_model.dart';
|
|
import 'package:didvan/models/new_statistic/total_type4_model.dart';
|
|
import 'package:didvan/models/requests/newstats_general.dart';
|
|
import 'package:didvan/providers/core.dart';
|
|
import 'package:didvan/services/network/request.dart';
|
|
import 'package:didvan/services/network/request_helper.dart';
|
|
|
|
class NewStockState extends CoreProvier {
|
|
int? categories;
|
|
int type = 1;
|
|
int page = 1;
|
|
int cat = 1;
|
|
String search = "";
|
|
String lastSearch = "";
|
|
int lastPage = 1;
|
|
List contents = [];
|
|
List<TotalContent> totalContent_type4 = [];
|
|
List<TotalType3Content> totalContent_type3 = [];
|
|
int? length;
|
|
int? length_type3;
|
|
int? length_type4;
|
|
|
|
Future<void> getStock({required int page}) async {
|
|
this.page = page;
|
|
|
|
lastSearch = search;
|
|
if (page == 1) {
|
|
contents.clear();
|
|
totalContent_type4.clear();
|
|
totalContent_type3.clear();
|
|
appState = AppState.busy;
|
|
}
|
|
|
|
final service = RequestService(RequestHelper.statisticGeneral(
|
|
args: StatisticsGeneralRequestArgs(
|
|
page: page,
|
|
q: search == '' ? null : search,
|
|
categories: 6,
|
|
type: type)));
|
|
|
|
await service.httpGet();
|
|
if (service.isSuccess) {
|
|
if (type == 1) {
|
|
contents.clear();
|
|
final content = ExchangeContentModel.fromJson(service.result);
|
|
contents.addAll(content.contents);
|
|
length = contents.length;
|
|
}
|
|
if (type == 2) {
|
|
contents.clear();
|
|
final content = ExchangeContentModel.fromJson(service.result);
|
|
contents.addAll(content.contents);
|
|
length = contents.length;
|
|
}
|
|
if (type == 3) {
|
|
contents.clear();
|
|
totalContent_type4.clear();
|
|
totalContent_type3.clear();
|
|
|
|
final List list = service.result["contents"];
|
|
length = list.length;
|
|
for (var i = 0; i < list.length; i++) {
|
|
if (list[i]['type'] == 4) {
|
|
totalContent_type4.add(TotalContent.fromJson(list[i]));
|
|
}
|
|
if (list[i]['type'] == 3) {
|
|
totalContent_type3.add(TotalType3Content.fromJson(list[i]));
|
|
}
|
|
}
|
|
length_type3 = totalContent_type3.length;
|
|
length_type4 = totalContent_type4.length;
|
|
}
|
|
if (type == 4) {
|
|
contents.clear();
|
|
final content = MetalContentModel.fromJson(service.result);
|
|
contents.addAll(content.contents);
|
|
length = contents.length;
|
|
}
|
|
|
|
appState = AppState.idle;
|
|
return;
|
|
}
|
|
appState = AppState.failed;
|
|
}
|
|
|
|
void init() {
|
|
Future.delayed(Duration.zero, () {
|
|
getStock(page: 1);
|
|
});
|
|
}
|
|
}
|