Skip to content

Commit

Permalink
Feat:[공통] PNDInfinitePagedList 위젯 기능 보완 #86
Browse files Browse the repository at this point in the history
  • Loading branch information
juan-rybczinski committed Feb 15, 2024
1 parent 6dfa845 commit 5f76a52
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const pagingSize = 20;
@riverpod
class BreedsPagingController extends _$BreedsPagingController {
@override
Raw<PagingController> build() {
Raw<PagingController<int, Breed>> build() {
final controller = PagingController<int, Breed>(firstPageKey: 1);

controller.addPageRequestListener((pageKey) => fetchPage(pageKey));
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 3 additions & 7 deletions lib/presentation/pages/pet/steps/register_pet_detail_view.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import 'package:flutter/material.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:infinite_scroll_pagination/infinite_scroll_pagination.dart';
import 'package:pets_next_door_flutter/features/pet/domain/breed.dart';
import 'package:pets_next_door_flutter/presentation/pages/pet/providers/breeds_paging_controller_provider.dart';
import 'package:pets_next_door_flutter/presentation/widgets/pagination/infinite_paged_list.dart';
Expand All @@ -10,13 +9,10 @@ class RegisterPetDetailView extends ConsumerWidget {

@override
Widget build(BuildContext context, WidgetRef ref) {
final pagingController = ref.watch(breedsPagingControllerProvider);

return PNDInfinitePagedList(
pagingController: pagingController,
builderDelegate: PagedChildBuilderDelegate<Breed>(
itemBuilder: <Breed>(context, breed, index) => Text(breed.name),
),
return PNDInfinitePagedList<Breed>(
pagingController: ref.watch(breedsPagingControllerProvider),
itemBuilder: (context, breed, index) => Text(breed.name),
);
}
}
24 changes: 5 additions & 19 deletions lib/presentation/pages/sos/layouts/sos_post_list_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,31 +23,17 @@ class _SosPostListView extends HookConsumerWidget with SosPostViewEvent {
return () => _scrollController.removeListener(_callBack);
}, [_scrollController]);

return RefreshIndicator(
color: AppColor.of.primaryGreen,
displacement: 0,
onRefresh: () => onListRefresh(ref),
child: PagedListView<int, SosPostEntity>.separated(
pagingController: ref.watch(sosPagingControllerProvider),
scrollController: _scrollController,
physics: AlwaysScrollableScrollPhysics(),
builderDelegate: PagedChildBuilderDelegate(
itemBuilder: (context, sosPost, index) => PndPostListTile.sosPage(
return PNDInfinitePagedList<SosPostEntity>(
pagingController: ref.watch(sosPagingControllerProvider),
scrollController: _scrollController,
itemBuilder: (context, sosPost, index) =>
PndPostListTile.sosPage(
imageUrl: sosPost.thumbnailUrl,
title: sosPost.title,
dateInfo:
'${sosPost.careStartAt.formatyyMMdd} ~ ${sosPost.careEndAt.formatyyMMdd}',
location: '용답동',
pay: '${sosPost.rewardPer} ${sosPost.reward}'),
firstPageProgressIndicatorBuilder: (context) => PndLoadingIndicator(),
newPageProgressIndicatorBuilder: (context) => PndLoadingIndicator(),
),
separatorBuilder: (context, index) => Divider(
height: 1,
thickness: 1,
color: AppColor.of.gray20,
),
),
);
}
}
4 changes: 1 addition & 3 deletions lib/presentation/pages/sos/sos_post_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter_hooks/flutter_hooks.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:infinite_scroll_pagination/infinite_scroll_pagination.dart';
import 'package:pets_next_door_flutter/core/constants/colors.dart';
import 'package:pets_next_door_flutter/core/enums/pet_type_filter.enum.dart';
import 'package:pets_next_door_flutter/core/enums/sort_type_filter.enum.dart';
import 'package:pets_next_door_flutter/core/helper/date_time_extension.dart';
Expand All @@ -14,8 +12,8 @@ import 'package:pets_next_door_flutter/presentation/pages/sos/sos_post_event.dar
import 'package:pets_next_door_flutter/presentation/widgets/button/radio_button.dart';
import 'package:pets_next_door_flutter/presentation/widgets/dropdown/dropdown_button.dart';
import 'package:pets_next_door_flutter/presentation/widgets/dropdown/dropdown_item.dart';
import 'package:pets_next_door_flutter/presentation/widgets/indicator/loading_indicator.dart';
import 'package:pets_next_door_flutter/presentation/widgets/list_tile/post_list_tile.dart';
import 'package:pets_next_door_flutter/presentation/widgets/pagination/infinite_paged_list.dart';

part 'layouts/pet_filter.dart';
part 'layouts/sort_filter.dart';
Expand Down
31 changes: 23 additions & 8 deletions lib/presentation/widgets/pagination/infinite_paged_list.dart
Original file line number Diff line number Diff line change
@@ -1,26 +1,41 @@
import 'package:flutter/material.dart';
import 'package:infinite_scroll_pagination/infinite_scroll_pagination.dart';
import 'package:pets_next_door_flutter/core/constants/sizes.dart';
import 'package:pets_next_door_flutter/core/constants/colors.dart';
import 'package:pets_next_door_flutter/presentation/widgets/indicator/loading_indicator.dart';

class PNDInfinitePagedList extends StatelessWidget {
class PNDInfinitePagedList<T> extends StatelessWidget {
PNDInfinitePagedList({
super.key,
required this.pagingController,
required this.builderDelegate,
this.scrollController,
required this.itemBuilder,
this.separatorBuilder,
});

final PagingController pagingController;
final PagedChildBuilderDelegate builderDelegate;
final PagingController<int, T> pagingController;
final ScrollController? scrollController;
final ItemWidgetBuilder<T> itemBuilder;
final IndexedWidgetBuilder? separatorBuilder;

@override
Widget build(BuildContext context) {
return RefreshIndicator(
child: PagedListView.separated(
color: AppColor.of.primaryGreen,
displacement: 0.0,
child: PagedListView<int, T>.separated(
pagingController: pagingController,
builderDelegate: builderDelegate,
separatorBuilder: separatorBuilder ?? (context, index) => gapH16,
scrollController: scrollController,
builderDelegate: PagedChildBuilderDelegate<T>(
itemBuilder: itemBuilder,
firstPageProgressIndicatorBuilder: (context) => PndLoadingIndicator(),
newPageProgressIndicatorBuilder: (context) => PndLoadingIndicator(),
),
separatorBuilder: separatorBuilder ??
(context, index) => Divider(
height: 1,
thickness: 1,
color: AppColor.of.gray20,
),
),
onRefresh: () => Future.sync(
() => pagingController.refresh(),
Expand Down

0 comments on commit 5f76a52

Please sign in to comment.