D1APP-100 pagination added to radars and news
This commit is contained in:
parent
9f828c637b
commit
2a581e0dd9
|
|
@ -55,6 +55,14 @@ class _NewsState extends State<News> {
|
||||||
onRetry: () => state.getNews(page: state.page),
|
onRetry: () => state.getNews(page: state.page),
|
||||||
state: state,
|
state: state,
|
||||||
builder: (context, state, index) {
|
builder: (context, state, index) {
|
||||||
|
index += 2;
|
||||||
|
if (index % 15 == 0 && index / 15 >= state.page) {
|
||||||
|
state.getNews(page: index ~/ 15 + 1);
|
||||||
|
}
|
||||||
|
index -= 2;
|
||||||
|
if (index >= state.news.length) {
|
||||||
|
return NewsOverview.placeholder;
|
||||||
|
}
|
||||||
final news = state.news[index];
|
final news = state.news[index];
|
||||||
return NewsOverview(
|
return NewsOverview(
|
||||||
news: news,
|
news: news,
|
||||||
|
|
@ -71,7 +79,8 @@ class _NewsState extends State<News> {
|
||||||
emptyState: EmptyResult(
|
emptyState: EmptyResult(
|
||||||
onNewSearch: () => _focusNode.requestFocus(),
|
onNewSearch: () => _focusNode.requestFocus(),
|
||||||
),
|
),
|
||||||
childCount: state.news.length,
|
childCount:
|
||||||
|
state.news.length + (state.lastPage == state.page ? 0 : 3),
|
||||||
itemPadding: const EdgeInsets.only(left: 16, right: 16, bottom: 16),
|
itemPadding: const EdgeInsets.only(left: 16, right: 16, bottom: 16),
|
||||||
placeholder: NewsOverview.placeholder,
|
placeholder: NewsOverview.placeholder,
|
||||||
),
|
),
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,7 @@ class NewsState extends CoreProvier {
|
||||||
String? startDate;
|
String? startDate;
|
||||||
String? endDate;
|
String? endDate;
|
||||||
int page = 1;
|
int page = 1;
|
||||||
|
int lastPage = 0;
|
||||||
|
|
||||||
final List<NewsOverviewData> news = [];
|
final List<NewsOverviewData> news = [];
|
||||||
|
|
||||||
|
|
@ -34,19 +35,21 @@ class NewsState extends CoreProvier {
|
||||||
Future<void> getNews({
|
Future<void> getNews({
|
||||||
required int page,
|
required int page,
|
||||||
}) async {
|
}) async {
|
||||||
if (this.page == page) {
|
this.page = page;
|
||||||
|
if (this.page == 1) {
|
||||||
news.clear();
|
news.clear();
|
||||||
}
|
}
|
||||||
this.page = page;
|
|
||||||
if (search != '') {
|
if (search != '') {
|
||||||
lastSearch = search;
|
lastSearch = search;
|
||||||
}
|
}
|
||||||
lastSearch = search;
|
lastSearch = search;
|
||||||
appState = AppState.busy;
|
if (page == 1) {
|
||||||
|
appState = AppState.busy;
|
||||||
|
}
|
||||||
final service = RequestService(
|
final service = RequestService(
|
||||||
RequestHelper.newsOverviews(
|
RequestHelper.newsOverviews(
|
||||||
args: NewsRequestArgs(
|
args: NewsRequestArgs(
|
||||||
page: 1,
|
page: page,
|
||||||
startDate: startDate?.split(' ').first,
|
startDate: startDate?.split(' ').first,
|
||||||
endDate: endDate?.split(' ').first,
|
endDate: endDate?.split(' ').first,
|
||||||
search: search == '' ? null : search,
|
search: search == '' ? null : search,
|
||||||
|
|
@ -55,6 +58,7 @@ class NewsState extends CoreProvier {
|
||||||
);
|
);
|
||||||
await service.httpGet();
|
await service.httpGet();
|
||||||
if (service.isSuccess) {
|
if (service.isSuccess) {
|
||||||
|
lastPage = service.result['lastPage'];
|
||||||
final newsList = service.result['news'];
|
final newsList = service.result['news'];
|
||||||
for (var i = 0; i < newsList.length; i++) {
|
for (var i = 0; i < newsList.length; i++) {
|
||||||
news.add(NewsOverviewData.fromJson(newsList[i]));
|
news.add(NewsOverviewData.fromJson(newsList[i]));
|
||||||
|
|
|
||||||
|
|
@ -113,7 +113,7 @@ class _RadarState extends State<Radar> {
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
SliverStateHandler<RadarState>(
|
SliverStateHandler<RadarState>(
|
||||||
onRetry: () => state.getRadarOverviewDatas(page: state.page),
|
onRetry: () => state.getRadars(page: state.page),
|
||||||
state: state,
|
state: state,
|
||||||
itemPadding: const EdgeInsets.only(
|
itemPadding: const EdgeInsets.only(
|
||||||
bottom: 20,
|
bottom: 20,
|
||||||
|
|
@ -128,6 +128,14 @@ class _RadarState extends State<Radar> {
|
||||||
),
|
),
|
||||||
placeholder: RadarOverview.placeholder,
|
placeholder: RadarOverview.placeholder,
|
||||||
builder: (context, state, index) {
|
builder: (context, state, index) {
|
||||||
|
index += 2;
|
||||||
|
if (index % 15 == 0 && index / 15 >= state.page) {
|
||||||
|
state.getRadars(page: index ~/ 15 + 1);
|
||||||
|
}
|
||||||
|
index -= 2;
|
||||||
|
if (index >= state.radars.length) {
|
||||||
|
return RadarOverview.placeholder;
|
||||||
|
}
|
||||||
final radar = state.radars[index];
|
final radar = state.radars[index];
|
||||||
return RadarOverview(
|
return RadarOverview(
|
||||||
radar: radar,
|
radar: radar,
|
||||||
|
|
@ -145,7 +153,8 @@ class _RadarState extends State<Radar> {
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
childCount: state.radars.length,
|
childCount: state.radars.length +
|
||||||
|
(state.lastPage == state.page ? 0 : 3),
|
||||||
),
|
),
|
||||||
if (state.radars.length == 1)
|
if (state.radars.length == 1)
|
||||||
const SliverToBoxAdapter(
|
const SliverToBoxAdapter(
|
||||||
|
|
@ -172,7 +181,7 @@ class _RadarState extends State<Radar> {
|
||||||
_timer?.cancel();
|
_timer?.cancel();
|
||||||
_timer = Timer(const Duration(seconds: 1), () {
|
_timer = Timer(const Duration(seconds: 1), () {
|
||||||
state.search = value;
|
state.search = value;
|
||||||
state.getRadarOverviewDatas(page: 1);
|
state.getRadars(page: 1);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -217,7 +226,7 @@ class _RadarState extends State<Radar> {
|
||||||
dismissTitle: 'حذف فیلتر',
|
dismissTitle: 'حذف فیلتر',
|
||||||
confrimTitle: 'نمایش نتایج',
|
confrimTitle: 'نمایش نتایج',
|
||||||
onDismissed: () => state.resetFilters(false),
|
onDismissed: () => state.resetFilters(false),
|
||||||
onConfirmed: () => state.getRadarOverviewDatas(page: 1),
|
onConfirmed: () => state.getRadars(page: 1),
|
||||||
content: Column(
|
content: Column(
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
children: [
|
children: [
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,7 @@ class RadarState extends CoreProvier {
|
||||||
String? startDate;
|
String? startDate;
|
||||||
String? endDate;
|
String? endDate;
|
||||||
int page = 1;
|
int page = 1;
|
||||||
|
int lastPage = 1;
|
||||||
bool isScrolled = false;
|
bool isScrolled = false;
|
||||||
bool shouldColapse = false;
|
bool shouldColapse = false;
|
||||||
final List<RadarCategory> selectedCats = [];
|
final List<RadarCategory> selectedCats = [];
|
||||||
|
|
@ -38,19 +39,21 @@ class RadarState extends CoreProvier {
|
||||||
lastSearch = '';
|
lastSearch = '';
|
||||||
isScrolled = false;
|
isScrolled = false;
|
||||||
if (!isInit) {
|
if (!isInit) {
|
||||||
getRadarOverviewDatas(page: 1);
|
getRadars(page: 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> getRadarOverviewDatas({
|
Future<void> getRadars({
|
||||||
required int page,
|
required int page,
|
||||||
}) async {
|
}) async {
|
||||||
|
this.page = page;
|
||||||
if (this.page == page) {
|
if (this.page == page) {
|
||||||
radars.clear();
|
radars.clear();
|
||||||
}
|
}
|
||||||
this.page = page;
|
|
||||||
lastSearch = search;
|
lastSearch = search;
|
||||||
appState = AppState.busy;
|
if (page == 1) {
|
||||||
|
appState = AppState.busy;
|
||||||
|
}
|
||||||
final RequestService service = RequestService(
|
final RequestService service = RequestService(
|
||||||
RequestHelper.radarOverviews(
|
RequestHelper.radarOverviews(
|
||||||
args: RadarRequestArgs(
|
args: RadarRequestArgs(
|
||||||
|
|
@ -64,8 +67,10 @@ class RadarState extends CoreProvier {
|
||||||
);
|
);
|
||||||
await service.httpGet();
|
await service.httpGet();
|
||||||
if (service.isSuccess) {
|
if (service.isSuccess) {
|
||||||
for (var i = 0; i < service.result['radars'].length; i++) {
|
lastPage = service.result['lastPage'];
|
||||||
radars.add(RadarOverviewData.fromJson(service.result['radars'][i]));
|
final radarsList = service.result['radars'];
|
||||||
|
for (var i = 0; i < radarsList.length; i++) {
|
||||||
|
radars.add(RadarOverviewData.fromJson(radarsList[i]));
|
||||||
}
|
}
|
||||||
if (searching || filtering || isColapsed || isCategorySelected) {
|
if (searching || filtering || isColapsed || isCategorySelected) {
|
||||||
shouldColapse = true;
|
shouldColapse = true;
|
||||||
|
|
@ -91,7 +96,7 @@ class RadarState extends CoreProvier {
|
||||||
void init() {
|
void init() {
|
||||||
resetFilters(true);
|
resetFilters(true);
|
||||||
Future.delayed(Duration.zero, () {
|
Future.delayed(Duration.zero, () {
|
||||||
getRadarOverviewDatas(page: 1);
|
getRadars(page: 1);
|
||||||
});
|
});
|
||||||
categories = [
|
categories = [
|
||||||
RadarCategory(
|
RadarCategory(
|
||||||
|
|
|
||||||
|
|
@ -98,7 +98,7 @@ class _CategoriesListState extends State<CategoriesList> {
|
||||||
duration: DesignConfig.lowAnimationDuration,
|
duration: DesignConfig.lowAnimationDuration,
|
||||||
curve: Curves.easeIn,
|
curve: Curves.easeIn,
|
||||||
);
|
);
|
||||||
state.getRadarOverviewDatas(page: 1);
|
state.getRadars(page: 1);
|
||||||
},
|
},
|
||||||
child: Container(
|
child: Container(
|
||||||
margin: const EdgeInsets.only(left: 12),
|
margin: const EdgeInsets.only(left: 12),
|
||||||
|
|
|
||||||
|
|
@ -29,7 +29,7 @@ class CategoryItem extends StatelessWidget {
|
||||||
if (category.id != 0) {
|
if (category.id != 0) {
|
||||||
state.selectedCats.add(category);
|
state.selectedCats.add(category);
|
||||||
}
|
}
|
||||||
state.getRadarOverviewDatas(page: 1);
|
state.getRadars(page: 1);
|
||||||
},
|
},
|
||||||
child: AnimatedContainer(
|
child: AnimatedContainer(
|
||||||
duration: DesignConfig.mediumAnimationDuration,
|
duration: DesignConfig.mediumAnimationDuration,
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,4 @@
|
||||||
import 'package:didvan/config/theme_data.dart';
|
|
||||||
import 'package:didvan/constants/app_icons.dart';
|
import 'package:didvan/constants/app_icons.dart';
|
||||||
import 'package:didvan/constants/assets.dart';
|
|
||||||
import 'package:didvan/pages/home/widgets/logo_app_bar.dart';
|
import 'package:didvan/pages/home/widgets/logo_app_bar.dart';
|
||||||
import 'package:didvan/widgets/didvan/icon_button.dart';
|
import 'package:didvan/widgets/didvan/icon_button.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
|
||||||
|
|
@ -44,7 +44,6 @@ class RadarOverview extends StatelessWidget {
|
||||||
child: Column(
|
child: Column(
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
children: [
|
children: [
|
||||||
const SizedBox(height: 8),
|
|
||||||
DidvanText(
|
DidvanText(
|
||||||
radar.title,
|
radar.title,
|
||||||
fontWeight: FontWeight.w600,
|
fontWeight: FontWeight.w600,
|
||||||
|
|
@ -139,11 +138,13 @@ class RadarOverview extends StatelessWidget {
|
||||||
child: Column(
|
child: Column(
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
children: [
|
children: [
|
||||||
|
const ShimmerPlaceholder(height: 16),
|
||||||
|
const SizedBox(height: 8),
|
||||||
const ShimmerPlaceholder(
|
const ShimmerPlaceholder(
|
||||||
width: 200,
|
width: 200,
|
||||||
height: 16,
|
height: 16,
|
||||||
),
|
),
|
||||||
const SizedBox(height: 8),
|
const SizedBox(height: 16),
|
||||||
const AspectRatio(aspectRatio: 16 / 9, child: ShimmerPlaceholder()),
|
const AspectRatio(aspectRatio: 16 / 9, child: ShimmerPlaceholder()),
|
||||||
const SizedBox(height: 8),
|
const SizedBox(height: 8),
|
||||||
Row(
|
Row(
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue