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