257 lines
6.3 KiB
Dart
257 lines
6.3 KiB
Dart
import 'dart:async';
|
|
|
|
import 'package:didvan/constants/assets.dart';
|
|
import 'package:didvan/models/category.dart';
|
|
import 'package:didvan/models/enums.dart';
|
|
import 'package:didvan/models/overview_data.dart';
|
|
import 'package:didvan/providers/core.dart';
|
|
import 'package:didvan/routes/routes.dart';
|
|
import 'package:didvan/services/network/request.dart';
|
|
import 'package:didvan/services/network/request_helper.dart';
|
|
import 'package:flutter/material.dart';
|
|
|
|
class MenuItemType {
|
|
final String label;
|
|
final String asset;
|
|
final String link;
|
|
|
|
MenuItemType({
|
|
required this.label,
|
|
required this.asset,
|
|
required this.link,
|
|
});
|
|
}
|
|
|
|
class HomeState extends CoreProvier {
|
|
int _currentPageIndex = 0;
|
|
String search = '';
|
|
String lastSearch = '';
|
|
Timer? timer;
|
|
String? startDate;
|
|
String? endDate;
|
|
int page = 1;
|
|
int lastPage = 1;
|
|
final List<CategoryData> selectedCats = [];
|
|
final List<OverviewData> results = [];
|
|
late TabController tabController;
|
|
int unreadCount = 0;
|
|
final FocusNode searchFieldFocusNode = FocusNode();
|
|
|
|
void resetFilters(bool isInit) {
|
|
startDate = null;
|
|
endDate = null;
|
|
selectedCats.clear();
|
|
search = '';
|
|
lastSearch = '';
|
|
if (!isInit) {
|
|
searchAll(page: 1);
|
|
}
|
|
}
|
|
|
|
set currentPageIndex(int value) {
|
|
_currentPageIndex = value;
|
|
notifyListeners();
|
|
}
|
|
|
|
int get currentPageIndex => _currentPageIndex;
|
|
|
|
List<MenuItemType> menuItems = [];
|
|
List<CategoryData> categories = [];
|
|
|
|
bool get filtering =>
|
|
selectedCats.isNotEmpty ||
|
|
startDate != null ||
|
|
endDate != null ||
|
|
search.isNotEmpty;
|
|
|
|
Future<void> searchMarks({required int page}) async {
|
|
this.page = page;
|
|
if (page == 1) {
|
|
results.clear();
|
|
appState = AppState.busy;
|
|
}
|
|
lastSearch = search;
|
|
final service = RequestService(
|
|
RequestHelper.searchAll(
|
|
page: page,
|
|
search: search,
|
|
endDate: endDate,
|
|
types: selectedCats.map((e) => e.id).toList(),
|
|
startDate: startDate,
|
|
),
|
|
);
|
|
await service.httpGet();
|
|
if (service.isSuccess) {
|
|
lastPage = service.result['lastPage'];
|
|
results.addAll(
|
|
List<OverviewData>.from(
|
|
service.result['contents'].map(
|
|
(e) => OverviewData.fromJson(e),
|
|
),
|
|
),
|
|
);
|
|
lastPage = service.result['lastPage'];
|
|
appState = AppState.idle;
|
|
return;
|
|
}
|
|
appState = AppState.failed;
|
|
}
|
|
|
|
Future<void> searchAll({required int page}) async {
|
|
this.page = page;
|
|
if (page == 1) {
|
|
results.clear();
|
|
appState = AppState.busy;
|
|
}
|
|
lastSearch = search;
|
|
final service = RequestService(
|
|
RequestHelper.searchAll(
|
|
page: page,
|
|
search: search,
|
|
endDate: endDate,
|
|
types: selectedCats.map((e) => e.id).toList(),
|
|
startDate: startDate,
|
|
),
|
|
);
|
|
await service.httpGet();
|
|
if (service.isSuccess) {
|
|
lastPage = service.result['lastPage'];
|
|
unreadCount = service.result['unread'] ?? unreadCount;
|
|
results.addAll(
|
|
List<OverviewData>.from(
|
|
service.result['contents'].map(
|
|
(e) => OverviewData.fromJson(e),
|
|
),
|
|
),
|
|
);
|
|
lastPage = service.result['lastPage'];
|
|
appState = AppState.idle;
|
|
return;
|
|
}
|
|
appState = AppState.failed;
|
|
}
|
|
|
|
final categoryFilters = [
|
|
CategoryData(id: 1, label: 'پویش افق'),
|
|
CategoryData(id: 2, label: 'دنیای فولاد'),
|
|
CategoryData(id: 3, label: 'ویدیوکست'),
|
|
CategoryData(id: 4, label: 'پادکست'),
|
|
CategoryData(id: 5, label: 'تحلیلهای راداری'),
|
|
CategoryData(id: 6, label: 'سها'),
|
|
];
|
|
|
|
void refresh() async {
|
|
menuItems = [
|
|
MenuItemType(
|
|
label: 'دنیای فولاد',
|
|
asset: Assets.fooladWorld,
|
|
link: Routes.news,
|
|
),
|
|
MenuItemType(
|
|
label: 'پویش افق',
|
|
asset: Assets.ofogh,
|
|
link: Routes.radars,
|
|
),
|
|
MenuItemType(
|
|
label: 'آمار و داده',
|
|
asset: Assets.stats,
|
|
link: 'tab-0',
|
|
),
|
|
MenuItemType(
|
|
label: 'سها',
|
|
asset: Assets.saha,
|
|
link: 'https://saha.didvan.app',
|
|
),
|
|
MenuItemType(
|
|
label: 'رادار استارتآپ',
|
|
asset: Assets.startup,
|
|
link: 'https://startup.didvan.app/',
|
|
),
|
|
MenuItemType(
|
|
label: 'رادار روند',
|
|
asset: Assets.trend,
|
|
link: 'https://trend.didvan.app/',
|
|
),
|
|
MenuItemType(
|
|
label: 'رادار تکنولوژی',
|
|
asset: Assets.tech,
|
|
link: 'https://tech.didvan.app/',
|
|
),
|
|
MenuItemType(
|
|
label: 'رادار ریسک',
|
|
asset: Assets.risk,
|
|
link: 'https://risk.didvan.app/',
|
|
),
|
|
MenuItemType(
|
|
label: 'ویدیوکست',
|
|
asset: Assets.videocast,
|
|
link: Routes.videocasts,
|
|
),
|
|
MenuItemType(
|
|
label: 'پادکست',
|
|
asset: Assets.podcast,
|
|
link: Routes.podcasts,
|
|
),
|
|
MenuItemType(
|
|
label: 'اینفوگرافی',
|
|
asset: Assets.startup,
|
|
link: Routes.infography,
|
|
),
|
|
];
|
|
|
|
categories = [
|
|
CategoryData(
|
|
id: 1,
|
|
label: 'اقتصادی',
|
|
asset: Assets.economicCategoryIcon,
|
|
),
|
|
CategoryData(
|
|
id: 2,
|
|
label: 'سیاسی',
|
|
asset: Assets.politicalCategoryIcon,
|
|
),
|
|
CategoryData(
|
|
id: 3,
|
|
label: 'فناوری',
|
|
asset: Assets.techCategoryIcon,
|
|
),
|
|
CategoryData(
|
|
id: 4,
|
|
label: 'کسب و کار',
|
|
asset: Assets.businessCategoryIcon,
|
|
),
|
|
CategoryData(
|
|
id: 5,
|
|
label: 'زیست محیطی',
|
|
asset: Assets.enviromentalCategoryIcon,
|
|
),
|
|
CategoryData(
|
|
id: 6,
|
|
label: 'اجتماعی',
|
|
asset: Assets.socialCategoryIcon,
|
|
),
|
|
CategoryData(
|
|
id: 1,
|
|
label: 'اقتصادی',
|
|
asset: Assets.economicCategoryIcon,
|
|
),
|
|
CategoryData(
|
|
id: 2,
|
|
label: 'سیاسی',
|
|
asset: Assets.politicalCategoryIcon,
|
|
),
|
|
CategoryData(
|
|
id: 3,
|
|
label: 'فناوری',
|
|
asset: Assets.techCategoryIcon,
|
|
),
|
|
CategoryData(
|
|
id: 4,
|
|
label: 'کسب و کار',
|
|
asset: Assets.businessCategoryIcon,
|
|
),
|
|
];
|
|
Future.delayed(Duration.zero, notifyListeners);
|
|
}
|
|
}
|