From 825b7c61dfc68fdcb366d34c13428037b15b1868 Mon Sep 17 00:00:00 2001 From: kimwest00 Date: Fri, 24 Nov 2023 14:16:01 +0900 Subject: [PATCH] =?UTF-8?q?refactor:#35=20view=20listview=20=ED=98=B8?= =?UTF-8?q?=EC=B6=9C=20=EB=A9=94=EC=86=8C=EB=93=9C=20=EB=B6=84=EB=A6=AC=20?= =?UTF-8?q?+=20=EC=A1=B0=EA=B1=B4=20=EC=88=98=EC=A0=95=20=EB=A7=A8?= =?UTF-8?q?=EB=81=9D=EC=97=90=EC=84=9C=EB=A7=8C=20=ED=98=B8=EC=B6=9C,=20cu?= =?UTF-8?q?rrentPage=20=EB=B3=80=EA=B2=BD=20api,=20controller=20=EB=A9=94?= =?UTF-8?q?=EC=86=8C=EB=93=9C=20=ED=86=B5=EC=9D=BC=20=ED=95=84=EC=9A=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../alarm/controller/alarm_controller.dart | 11 ++-- lib/modules/alarm/view/alarm_view.dart | 12 ++--- .../controller/burning_match_controller.dart | 4 +- .../buring_match/view/burning_match_view.dart | 9 +--- .../donate/controller/donate_controller.dart | 4 +- lib/modules/donate/view/donate_view.dart | 52 +++++++++++-------- .../donation_search_controller.dart | 11 ++-- .../view/donation_search_view.dart | 11 +--- .../event/controller/event_controller.dart | 9 ++-- lib/modules/event/view/event_view.dart | 13 +++-- .../home/controller/home_controller.dart | 3 +- lib/modules/home/view/home_view.dart | 20 +++---- .../controller/like_project_controller.dart | 5 +- .../like_project/view/like_project_view.dart | 11 ++-- .../notice/controller/notice_controller.dart | 6 +-- lib/modules/notice/view/notice_view.dart | 9 +--- .../controller/project_controller.dart | 10 ++-- lib/modules/project/view/project_view.dart | 26 +++++----- lib/provider/api/comment_api.dart | 2 + lib/provider/api/flame_api.dart | 10 +++- lib/provider/api/mypage_api.dart | 22 ++++---- lib/provider/api/notice_api.dart | 2 + lib/provider/api/notification_api.dart | 2 + lib/provider/api/project_api.dart | 4 ++ lib/provider/api/util/global_api_field.dart | 2 +- .../api/util/pagination_function.dart | 16 ++++++ 26 files changed, 145 insertions(+), 141 deletions(-) create mode 100644 lib/provider/api/util/pagination_function.dart diff --git a/lib/modules/alarm/controller/alarm_controller.dart b/lib/modules/alarm/controller/alarm_controller.dart index ba1cd46c..9779e343 100644 --- a/lib/modules/alarm/controller/alarm_controller.dart +++ b/lib/modules/alarm/controller/alarm_controller.dart @@ -9,18 +9,17 @@ class AlarmController extends GetxController { static AlarmController get to => Get.find(); RxList notifcationList = [].obs; - Future getMoreNotification({required int index}) async { + Future getMoreNotification(int index) async { logger.d( "2: 총 페이지수 : ${NotificationApi.notification.totalCnt ~/ PAGINATION_SIZE}, 불러오고자 하는 페이지: ${index}"); - if (!(NotificationApi.notification.totalCnt ~/ PAGINATION_SIZE < index) && - !NotificationApi.notification.isLast) { - NotificationApi.notification.currentpage = index; - notifcationList.addAll(await NotificationApi.getNotificationList(getMore: true)); + if (!NotificationApi.notification.isLast) { + notifcationList + .addAll(await NotificationApi.getNotificationList(getMore: true)); } } @override - void onInit() async{ + void onInit() async { super.onInit(); notifcationList.assignAll(await NotificationApi.getNotificationList()); } diff --git a/lib/modules/alarm/view/alarm_view.dart b/lib/modules/alarm/view/alarm_view.dart index 60638285..327073e0 100644 --- a/lib/modules/alarm/view/alarm_view.dart +++ b/lib/modules/alarm/view/alarm_view.dart @@ -1,6 +1,7 @@ import 'package:flutter/material.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:get/get.dart'; +import 'package:match/provider/api/util/pagination_function.dart'; import 'package:match/util/components/global_app_bar.dart'; import 'package:match/util/components/global_widget.dart'; import '../../../provider/api/util/global_api_field.dart'; @@ -20,13 +21,10 @@ class AlarmScreen extends GetView { child: ListView.separated( itemCount: controller.notifcationList.length, itemBuilder: (context, index) { - if (index % (PAGINATION_SIZE - 1) == 0 && index != 0) { - logger.d("1. getMore 호출!"); - Future.wait({ - controller.getMoreNotification( - index: index ~/ (PAGINATION_SIZE - 1)) - }); - } + getMoreData( + index: index, + totalCnt: controller.notifcationList.length, + getMore: controller.getMoreNotification); final alarm = controller.notifcationList[index]; return CommonListItem( category: alarm.notificationsType, diff --git a/lib/modules/buring_match/controller/burning_match_controller.dart b/lib/modules/buring_match/controller/burning_match_controller.dart index d1878a8d..96725087 100644 --- a/lib/modules/buring_match/controller/burning_match_controller.dart +++ b/lib/modules/buring_match/controller/burning_match_controller.dart @@ -27,9 +27,7 @@ class BurningMatchController extends GetxController { ///

Listview builder에서 호출하는 pagination 추가 호출 함수

///* 총 데이터 수와 비교하여, 페이지를 더 늘릴수있다면 api 호출, 그렇지 않다면 호출 X Future getMoreFlameHistory(int index) async { - if (!(FlameApi.burningFlame.totalCnt ~/ PAGINATION_SIZE < index) && - !FlameApi.burningFlame.isLast) { - FlameApi.burningFlame.currentpage = index; + if (!FlameApi.burningFlame.isLast) { flameHistories.addAll(await FlameApi.getFlameDetailBottomList( donationId: id, getMore: true)); } diff --git a/lib/modules/buring_match/view/burning_match_view.dart b/lib/modules/buring_match/view/burning_match_view.dart index 7fb6f48d..2a351587 100644 --- a/lib/modules/buring_match/view/burning_match_view.dart +++ b/lib/modules/buring_match/view/burning_match_view.dart @@ -4,6 +4,7 @@ import 'package:get/get.dart'; import 'package:match/modules/buring_match/controller/burning_match_controller.dart'; import 'package:match/modules/buring_match/widget/match_record_widget.dart'; import 'package:match/modules/home/widget/home_widget.dart'; +import 'package:match/provider/api/util/pagination_function.dart'; import 'package:match/util/const/style/global_color.dart'; import 'package:match/util/const/style/global_text_styles.dart'; import '../../../provider/api/util/global_api_field.dart'; @@ -82,13 +83,7 @@ class BurningMatchScreen extends GetView { itemBuilder: (context, index) { logger.d(index); //pagination 처리 - if (index % (PAGINATION_SIZE - 1) == 0 && - index != 0) { - Future.wait({ - controller.getMoreFlameHistory( - index ~/ (PAGINATION_SIZE - 1)) - }); - } + getMoreData(index: index, totalCnt: controller.flameHistories.length, getMore: controller.getMoreFlameHistory); final history = controller.flameHistories[index]; return MatchRecord( title: history.histories, diff --git a/lib/modules/donate/controller/donate_controller.dart b/lib/modules/donate/controller/donate_controller.dart index 220f87f1..12a424d5 100644 --- a/lib/modules/donate/controller/donate_controller.dart +++ b/lib/modules/donate/controller/donate_controller.dart @@ -20,9 +20,7 @@ class DonateController extends GetxController { ///pagination 함수 Future getMoreProject(int index) async { - if (!(ProjectApi.project.totalCnt ~/ PAGINATION_SIZE < index) && - !ProjectApi.project.isLast) { - ProjectApi.project.currentpage = index; + if (!ProjectApi.project.isLast) { projectList.addAll(await ProjectApi.getProjectList( type: selectType.value, getMore: true)); } diff --git a/lib/modules/donate/view/donate_view.dart b/lib/modules/donate/view/donate_view.dart index 96a75ff2..f6cc5c06 100644 --- a/lib/modules/donate/view/donate_view.dart +++ b/lib/modules/donate/view/donate_view.dart @@ -3,6 +3,7 @@ import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:flutter_svg/flutter_svg.dart'; import 'package:get/get.dart'; import 'package:match/modules/donate/widget/donate_widget.dart'; +import 'package:match/provider/api/util/pagination_function.dart'; import 'package:match/util/components/global_widget.dart'; import 'package:match/util/const/style/global_text_styles.dart'; import '../../../model/enum/project_type.dart'; @@ -29,8 +30,8 @@ class DonateScreen extends GetView { children: [ ///*1.제목 header Padding( - padding: - EdgeInsets.symmetric(vertical: 8.h).copyWith(bottom: 25.h), + padding: EdgeInsets.symmetric(vertical: 8.h) + .copyWith(bottom: 25.h), child: Row( children: [ Expanded( @@ -56,6 +57,7 @@ class DonateScreen extends GetView { ], ), ), + ///*2.프로젝트 카테고리 SizedBox( height: 76.h, @@ -98,29 +100,33 @@ class DonateScreen extends GetView { }), ), ), + ///*3.프로젝트 리스트 Expanded( - child: controller.projectList.isNotEmpty?ListView.builder( - shrinkWrap: true, - itemCount: controller.projectList.length, - itemBuilder: (context, index) { - if (index % (PAGINATION_SIZE - 1) == 0 && index != 0) { - Future.wait({ - controller.getMoreProject(index ~/ (PAGINATION_SIZE - 1)) - }); - } - final project = controller.projectList[index]; - return Container( - padding: EdgeInsets.symmetric(vertical: 8.h), - margin: EdgeInsets.only( - //상단,하단 margin 예외 처리 - top: index == 0 ? 14.h : 0.h, - bottom: index == controller.projectList.length - 1 - ? 14.h - : 0.h), - child: ProjectWidget(project: project)); - }, - ):emptyWidget(), + child: controller.projectList.isNotEmpty + ? ListView.builder( + shrinkWrap: true, + itemCount: controller.projectList.length, + itemBuilder: (context, index) { + getMoreData( + index: index, + totalCnt: controller.projectList.length, + getMore: controller.getMoreProject); + + final project = controller.projectList[index]; + return Container( + padding: EdgeInsets.symmetric(vertical: 8.h), + margin: EdgeInsets.only( + //상단,하단 margin 예외 처리 + top: index == 0 ? 14.h : 0.h, + bottom: index == + controller.projectList.length - 1 + ? 14.h + : 0.h), + child: ProjectWidget(project: project)); + }, + ) + : emptyWidget(), ), ], ), diff --git a/lib/modules/donation_search/controller/donation_search_controller.dart b/lib/modules/donation_search/controller/donation_search_controller.dart index 33979f19..7a82bd30 100644 --- a/lib/modules/donation_search/controller/donation_search_controller.dart +++ b/lib/modules/donation_search/controller/donation_search_controller.dart @@ -24,7 +24,7 @@ class DonationSearchController extends GetxController { ///* 추천 검색어 리스트 RxList recommendSearchList = List.generate(10, (index) => "").obs; - + RxString currentSearchText = "".obs; ///▼ 입력을 시작하고, 아무 action이 없을시 ///자동으로 검색되는 기능을 위한 변수 @@ -62,18 +62,17 @@ class DonationSearchController extends GetxController { totalSearchLength.value = ProjectApi.project.totalCnt; searchStatus.value = SEARCH_STATUS.SEARCH; + currentSearchText.value = content; } ///* 검색 결과 api에대한 pagination을 처리하는 함수 - Future getMoreSearchList( - {required String content, required int index}) async { - if (!(ProjectApi.project.totalCnt ~/ PAGINATION_SIZE < index) && - !ProjectApi.project.isLast) { + Future getMoreSearchList(int index) async { + if (!ProjectApi.project.isLast) { ProjectApi.project.currentpage = index; searchStatus.value = SEARCH_STATUS.SEARCH; projectList.addAll(await ProjectApi.getProjectList( getMore: true, - content: content, + content: currentSearchText.value , )); } } diff --git a/lib/modules/donation_search/view/donation_search_view.dart b/lib/modules/donation_search/view/donation_search_view.dart index 1e517a37..dcc7b6e8 100644 --- a/lib/modules/donation_search/view/donation_search_view.dart +++ b/lib/modules/donation_search/view/donation_search_view.dart @@ -2,6 +2,7 @@ import 'dart:async'; import 'package:flutter/material.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:get/get.dart'; +import 'package:match/provider/api/util/pagination_function.dart'; import '../../../model/enum/search_status.dart'; import '../../../provider/api/util/global_api_field.dart'; import '../../../util/components/gloabl_text_field.dart'; @@ -110,15 +111,7 @@ class DonationSearchScreen extends GetView { itemCount: controller.projectList.length, itemBuilder: (context, index) { //검색 결과 리스트 스크롤시 pagination - if (index % (PAGINATION_SIZE - 1) == 0 && - index != 0) { - Future.wait({ - controller.getMoreSearchList( - content: controller - .searchTextController.value.text, - index: index ~/ (PAGINATION_SIZE - 1)) - }); - } + getMoreData(index: index, totalCnt: controller.projectList.length, getMore: controller.getMoreSearchList); final project = controller.projectList[index]; return Container( padding: EdgeInsets.symmetric( diff --git a/lib/modules/event/controller/event_controller.dart b/lib/modules/event/controller/event_controller.dart index 661c4ea6..e2986ccf 100755 --- a/lib/modules/event/controller/event_controller.dart +++ b/lib/modules/event/controller/event_controller.dart @@ -10,15 +10,14 @@ class EventController extends GetxController { RxList eventList = [].obs; ///* pagination 함수 - Future getMoreNotice({required int index}) async { - if (!(EventApi.event.totalCnt ~/ PAGINATION_SIZE < index) && - !EventApi.event.isLast) { - EventApi.event.currentpage = index; + Future getMoreNotice(int index) async { + if (!EventApi.event.isLast) { eventList.addAll(await EventApi.getEventList(getMore: true)); } } + @override - void onInit() async{ + void onInit() async { super.onInit(); eventList.assignAll(await EventApi.getEventList()); } diff --git a/lib/modules/event/view/event_view.dart b/lib/modules/event/view/event_view.dart index 1a4671dc..52fab52f 100755 --- a/lib/modules/event/view/event_view.dart +++ b/lib/modules/event/view/event_view.dart @@ -3,6 +3,7 @@ import 'package:flutter/material.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:get/get.dart'; import 'package:match/modules/event/widget/event_widget.dart'; +import 'package:match/provider/api/util/pagination_function.dart'; import 'package:match/util/const/style/global_text_styles.dart'; import '../../../provider/api/util/global_api_field.dart'; @@ -53,13 +54,11 @@ class EventScreen extends GetView { : CarouselSlider.builder( itemCount: controller.eventList.length, itemBuilder: (context, index, realIndex) { - if (index % (PAGINATION_SIZE - 1) == 0 && - index != 0) { - Future.wait({ - controller.getMoreNotice( - index: index ~/ (PAGINATION_SIZE - 1)) - }); - } + getMoreData( + index: index, + totalCnt: controller.eventList.length, + getMore: controller.getMoreNotice); + ///* event detail 라우팅은 해당 위젯 내부에서 구현 return EventWidget( event: controller.eventList[index]); diff --git a/lib/modules/home/controller/home_controller.dart b/lib/modules/home/controller/home_controller.dart index 554121bd..71686b6d 100644 --- a/lib/modules/home/controller/home_controller.dart +++ b/lib/modules/home/controller/home_controller.dart @@ -33,9 +33,8 @@ class HomeController extends GetxController { if (!(FlameApi.burningFlame.totalCnt ~/ PAGINATION_SIZE < FlameApi.burningFlame.currentpage + 1) && !FlameApi.burningFlame.isLast) { - FlameApi.burningFlame.currentpage = index; - flameList.addAll(await FlameApi.getBurningFlameList(getMore: true)); + FlameApi.burningFlame.currentpage = index; } } diff --git a/lib/modules/home/view/home_view.dart b/lib/modules/home/view/home_view.dart index 8796cf6e..540669dd 100644 --- a/lib/modules/home/view/home_view.dart +++ b/lib/modules/home/view/home_view.dart @@ -8,6 +8,7 @@ import 'package:match/util/const/global_variable.dart'; import 'package:match/util/const/style/global_color.dart'; import 'package:match/util/const/style/global_text_styles.dart'; import '../../../provider/api/util/global_api_field.dart'; +import '../../../provider/api/util/pagination_function.dart'; import '../../../util/components/global_widget.dart'; import '../../../util/const/style/global_skeleton.dart'; import '../controller/home_controller.dart'; @@ -129,13 +130,12 @@ class HomeScreen extends GetView { WidgetsBinding.instance.addPostFrameCallback((_) { controller.currentIdx.value = index + 1; }); - if (index % (PAGINATION_SIZE - 1) == 0 && - index != 0) { - Future.wait({ - controller.getMoreFlame( - index ~/ (PAGINATION_SIZE - 1)) - }); - } + + getMoreData( + index: index, + totalCnt: controller.flameList.length, + getMore: controller.getMoreFlame); + final flame = controller.flameList[index]; return Column( children: [ @@ -165,6 +165,7 @@ class HomeScreen extends GetView { ), ); } + //TODO: kakao -> app routing 테스트 이전 Widget shareChip({required String imgUrl, required int projectId}) { return GestureDetector( @@ -175,7 +176,7 @@ class HomeScreen extends GetView { child: Container( padding: EdgeInsets.symmetric(horizontal: 4.w, vertical: 5.h), decoration: BoxDecoration( - color: AppColors.grey0, + color: AppColors.grey0, borderRadius: BorderRadius.circular(5.r), border: Border.all(color: AppColors.grey1)), child: Row( @@ -187,7 +188,8 @@ class HomeScreen extends GetView { ), Text( "공유하기", - style: AppTextStyles.L1Medium12.copyWith(color: AppColors.grey5), + style: + AppTextStyles.L1Medium12.copyWith(color: AppColors.grey5), ) ], ), diff --git a/lib/modules/like_project/controller/like_project_controller.dart b/lib/modules/like_project/controller/like_project_controller.dart index 19f9585b..9ce57e81 100644 --- a/lib/modules/like_project/controller/like_project_controller.dart +++ b/lib/modules/like_project/controller/like_project_controller.dart @@ -9,11 +9,10 @@ class LikeProjectController extends GetxController { RxList projectList = [].obs; ///* 프로젝트 pagination - Future getMoreProject({required int index}) async { + Future getMoreProject(int index) async { logger.d( "2: 총 페이지수 : ${MypageApi.likes.totalCnt ~/ PAGINATION_SIZE}, 불러오고자 하는 페이지: ${index}"); - if (!(MypageApi.likes.totalCnt ~/ PAGINATION_SIZE < index) && - !MypageApi.likes.isLast) { + if (!MypageApi.likes.isLast) { MypageApi.likes.currentpage = index; projectList.addAll(await MypageApi.getLikeList( getMore: true, diff --git a/lib/modules/like_project/view/like_project_view.dart b/lib/modules/like_project/view/like_project_view.dart index d25fb33d..ef81e40f 100644 --- a/lib/modules/like_project/view/like_project_view.dart +++ b/lib/modules/like_project/view/like_project_view.dart @@ -4,6 +4,7 @@ import 'package:get/get.dart'; import 'package:match/modules/like_project/controller/like_project_controller.dart'; import '../../../provider/api/util/global_api_field.dart'; +import '../../../provider/api/util/pagination_function.dart'; import '../../../util/components/global_app_bar.dart'; import '../../donate/widget/donate_widget.dart'; @@ -22,12 +23,10 @@ class LikeProjectScreen extends GetView { itemCount: controller.projectList.length, itemBuilder: (context, index) { //pagination 처리 - if (index % (PAGINATION_SIZE - 1) == 0 && index != 0) { - Future.wait({ - controller.getMoreProject( - index: index ~/ (PAGINATION_SIZE - 1)) - }); - } + getMoreData( + index: index, + totalCnt: controller.projectList.length, + getMore: controller.getMoreProject); final project = controller.projectList[index]; return ProjectWidget(project: project); }, diff --git a/lib/modules/notice/controller/notice_controller.dart b/lib/modules/notice/controller/notice_controller.dart index 897c616d..4662694c 100644 --- a/lib/modules/notice/controller/notice_controller.dart +++ b/lib/modules/notice/controller/notice_controller.dart @@ -9,12 +9,10 @@ class NoticeController extends GetxController { RxList noticeList = [].obs; RxInt totalNotice = 0.obs; - Future getMoreNotice({required int index}) async { + Future getMoreNotice(int index) async { logger.d( "2: 총 페이지수 : ${NoticeApi.notice.totalCnt ~/ PAGINATION_SIZE}, 불러오고자 하는 페이지: ${index}"); - if (!(NoticeApi.notice.totalCnt ~/ PAGINATION_SIZE < index) && - !NoticeApi.notice.isLast) { - NoticeApi.notice.currentpage = index; + if (!NoticeApi.notice.isLast) { noticeList.addAll(await NoticeApi.getNoticeList(getMore: true)); } } diff --git a/lib/modules/notice/view/notice_view.dart b/lib/modules/notice/view/notice_view.dart index bd486a77..e0a61c02 100644 --- a/lib/modules/notice/view/notice_view.dart +++ b/lib/modules/notice/view/notice_view.dart @@ -1,6 +1,7 @@ import 'package:flutter/material.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:get/get.dart'; +import 'package:match/provider/api/util/pagination_function.dart'; import 'package:match/util/components/global_app_bar.dart'; import 'package:match/util/components/global_widget.dart'; import '../../../provider/api/util/global_api_field.dart'; @@ -46,13 +47,7 @@ class NoticeScreen extends GetView { shrinkWrap: true, itemCount: controller.noticeList.length, itemBuilder: (context, index) { - if (index % (PAGINATION_SIZE - 1) == 0 && index != 0) { - logger.d("1. getMore 호출!"); - Future.wait({ - controller.getMoreNotice( - index: index ~/ (PAGINATION_SIZE - 1)) - }); - } + getMoreData(index: index, totalCnt: controller.noticeList.length, getMore: controller.getMoreNotice); final notice = controller.noticeList[index]; return CommonListItem( category: notice.noticeType, diff --git a/lib/modules/project/controller/project_controller.dart b/lib/modules/project/controller/project_controller.dart index 0dc77fea..0fb8be03 100644 --- a/lib/modules/project/controller/project_controller.dart +++ b/lib/modules/project/controller/project_controller.dart @@ -45,12 +45,11 @@ class ProjectController extends GetxController { await ProjectApi.getProjectHistoryList(projectId: projectId)); } ///* 프로젝트 기록 pagination - Future getMoreProjectHistory({required int index}) async { + Future getMoreProjectHistory(int index) async { logger.d( "2: 총 페이지수 : ${ProjectApi.project.totalCnt ~/ PAGINATION_SIZE}, 불러오고자 하는 페이지: ${index}"); - if (!(ProjectApi.project.totalCnt ~/ PAGINATION_SIZE < index) && + if ( !ProjectApi.project.isLast) { - ProjectApi.project.currentpage = index; projectHistories.addAll(await ProjectApi.getProjectHistoryList( projectId: projectId, getMore: true, @@ -63,12 +62,11 @@ class ProjectController extends GetxController { Rx searchStatus = SEARCH_STATUS.INIT.obs; ///* 응원 댓글 pagination - Future getMoreComments({required int index}) async { + Future getMoreComments( int index) async { logger.d( "2: 총 페이지수 : ${CommentApi.comments.totalCnt ~/ PAGINATION_SIZE}, 불러오고자 하는 페이지: ${index}"); - if (!(CommentApi.comments.totalCnt ~/ PAGINATION_SIZE < index) && + if ( !CommentApi.comments.isLast) { - CommentApi.comments.currentpage = index; comments.addAll(await CommentApi.getComments( projectId: projectId, getMore: true, diff --git a/lib/modules/project/view/project_view.dart b/lib/modules/project/view/project_view.dart index cc385c4b..c042cd8d 100644 --- a/lib/modules/project/view/project_view.dart +++ b/lib/modules/project/view/project_view.dart @@ -7,6 +7,7 @@ import 'package:match/model/enum/regular_status.dart'; import 'package:match/modules/payment/binding/payment_binding.dart'; import 'package:match/modules/payment/view/payment_donator_info_view.dart'; import 'package:match/modules/project/widget/project_widget.dart'; +import 'package:match/provider/api/util/pagination_function.dart'; import 'package:match/util/const/style/global_logger.dart'; import '../../../model/comment/comment.dart'; import '../../../model/enum/search_status.dart'; @@ -119,7 +120,8 @@ class ProjectScreen extends GetView { spacing: -10.w, children: controller .projectDetail.value.userProfileImages - .map((e) => profileItem(size: 40, profileUrl: e)) + .map((e) => + profileItem(size: 40, profileUrl: e)) .toList(), ), controller.projectDetail.value.totalDonationCnt > @@ -202,12 +204,10 @@ class ProjectScreen extends GetView { }, itemBuilder: (context, index) { //pagination 처리 - if (index % (PAGINATION_SIZE - 1) == 0 && index != 0) { - Future.wait({ - controller.getMoreProjectHistory( - index: index ~/ (PAGINATION_SIZE - 1)) - }); - } + getMoreData( + index: index, + totalCnt: controller.projectHistories.length, + getMore: controller.getMoreProjectHistory); final history = controller.projectHistories[index]; return Padding( padding: EdgeInsets.symmetric(horizontal: 20.w), @@ -223,7 +223,7 @@ class ProjectScreen extends GetView { ///* 세 번째 탭 (응원) Obx( - ()=> ListView.separated( + () => ListView.separated( controller: controller.scrollController.value, physics: const NeverScrollableScrollPhysics(), itemCount: controller.comments.length, @@ -232,12 +232,10 @@ class ProjectScreen extends GetView { }, itemBuilder: (context, index) { //pagination 처리 - if (index % (PAGINATION_SIZE - 1) == 0 && index != 0) { - Future.wait({ - controller.getMoreComments( - index: index ~/ (PAGINATION_SIZE - 1)) - }); - } + getMoreData( + index: index, + totalCnt: controller.comments.length, + getMore: controller.getMoreComments); final comment = controller.comments[index]; return Padding( padding: EdgeInsets.symmetric(horizontal: 20.w) diff --git a/lib/provider/api/comment_api.dart b/lib/provider/api/comment_api.dart index 8a6a938f..e2f532a1 100644 --- a/lib/provider/api/comment_api.dart +++ b/lib/provider/api/comment_api.dart @@ -18,6 +18,8 @@ class CommentApi { {bool getMore = false, required int projectId}) async { if (!getMore) { comments.currentpage = 0; + } else { + comments.currentpage += 1; } var queryParameters = { "page": comments.currentpage, diff --git a/lib/provider/api/flame_api.dart b/lib/provider/api/flame_api.dart index ed281c3c..39438e59 100644 --- a/lib/provider/api/flame_api.dart +++ b/lib/provider/api/flame_api.dart @@ -19,6 +19,8 @@ class FlameApi { try { if (!getMore) { burningFlame.currentpage = 0; + } else { + burningFlame.currentpage += 1; } Response response = await DioServices() .to() @@ -61,6 +63,8 @@ class FlameApi { logger.d("api호출 성공"); if (!getMore) { detailFlameBottom.currentpage = 0; + } else { + detailFlameBottom.currentpage += 1; } Response response = await DioServices() .to() @@ -73,8 +77,10 @@ class FlameApi { detailFlameBottom.isLast = response.data[RESULT][LAST]; logger.d( "pagination 정보: totalCnt:${detailFlameBottom.totalCnt}, currentPage:${detailFlameBottom.currentpage} isLast:${detailFlameBottom.isLast}"); - return List.generate(response.data[RESULT][CONTENTS].length, - (index) => MatchHistory.fromJson(response.data[RESULT][CONTENTS][index])); + return List.generate( + response.data[RESULT][CONTENTS].length, + (index) => + MatchHistory.fromJson(response.data[RESULT][CONTENTS][index])); } catch (e) { logger.e(e.toString()); return []; diff --git a/lib/provider/api/mypage_api.dart b/lib/provider/api/mypage_api.dart index 07a24a16..37f8f907 100644 --- a/lib/provider/api/mypage_api.dart +++ b/lib/provider/api/mypage_api.dart @@ -104,9 +104,9 @@ class MypageApi { logger.e(deviceId); DioServices().addHeader("DEVICE_ID", deviceId ?? ""); Response response = await DioServices().to().get( - "/users/logout", - queryParameters: {"DEVICE_ID": deviceId}, - ); + "/users/logout", + queryParameters: {"DEVICE_ID": deviceId}, + ); if (response.data[SUCCESS]) { DioServices().removeHeader('DEVICE_ID'); } @@ -122,8 +122,8 @@ class MypageApi { static Future signOut() async { try { Response response = await DioServices().to().delete( - "/users", - ); + "/users", + ); return response.data[SUCCESS]; } catch (e) { Fluttertoast.showToast(msg: "회원탈퇴에 실패하였습니다. ${e}"); @@ -131,13 +131,11 @@ class MypageApi { } } -///

2-13 API | 회원탈퇴

- static Future signOutApple({ - required String code - }) async { + ///

2-13 API | 회원탈퇴

+ static Future signOutApple({required String code}) async { try { - Response response = await DioServices().to().delete("/users/apple", - data: {"code": code}); + Response response = + await DioServices().to().delete("/users/apple", data: {"code": code}); return response.data[SUCCESS]; } catch (e) { @@ -156,6 +154,8 @@ class MypageApi { try { if (!getMore) { likes.currentpage = 0; + } else { + likes.currentpage += 1; } var queryParameters = { "page": likes.currentpage, diff --git a/lib/provider/api/notice_api.dart b/lib/provider/api/notice_api.dart index 1f9b7df6..826cdb20 100644 --- a/lib/provider/api/notice_api.dart +++ b/lib/provider/api/notice_api.dart @@ -16,6 +16,8 @@ class NoticeApi { try { if (!getMore) { notice.currentpage = 0; + } else { + notice.currentpage += 1; } Response response = await DioServices().to().get("/notices", queryParameters: { diff --git a/lib/provider/api/notification_api.dart b/lib/provider/api/notification_api.dart index 8f97a909..d1c14aab 100644 --- a/lib/provider/api/notification_api.dart +++ b/lib/provider/api/notification_api.dart @@ -35,6 +35,8 @@ class NotificationApi { try { if (!getMore) { notification.currentpage = 0; + } else { + notification.currentpage += 1; } Response response = await DioServices().to().get("/notifications", queryParameters: { diff --git a/lib/provider/api/project_api.dart b/lib/provider/api/project_api.dart index fb055f7e..53cf6e30 100644 --- a/lib/provider/api/project_api.dart +++ b/lib/provider/api/project_api.dart @@ -26,6 +26,8 @@ class ProjectApi { }) async { if (!getMore) { project.currentpage = 0; + } else { + project.currentpage += 1; } var queryParameters = { "page": project.currentpage, @@ -99,6 +101,8 @@ class ProjectApi { try { if (!getMore) { projectHistory.currentpage = 0; + } else { + projectHistory.currentpage += 1; } Response response = await DioServices() .to() diff --git a/lib/provider/api/util/global_api_field.dart b/lib/provider/api/util/global_api_field.dart index fab31da4..b93e7c8a 100644 --- a/lib/provider/api/util/global_api_field.dart +++ b/lib/provider/api/util/global_api_field.dart @@ -7,6 +7,6 @@ const String TOTAL = "totalCnt"; const String CONTENTS = "contents"; const String NOTIFICATIONS = "notificationLists"; ///* pagination 기본 호출 단위 -const int PAGINATION_SIZE = 20; +const int PAGINATION_SIZE = 10; const String TOKEN_HEADER = 'X-AUTH-TOKEN'; const String REFRESH_HEADER = 'X-REFRESH-TOKEN'; \ No newline at end of file diff --git a/lib/provider/api/util/pagination_function.dart b/lib/provider/api/util/pagination_function.dart new file mode 100644 index 00000000..22e3d41e --- /dev/null +++ b/lib/provider/api/util/pagination_function.dart @@ -0,0 +1,16 @@ +import 'global_api_field.dart'; + +///

Pagination 조건

+///1. 현재 index가 마지막 index일때 +///2. 현재 index가 0이 아닐때 +///3. 현재 list의 총 길이가 PAGINATION_SIZE의 배수일때 +Future getMoreData( + {required int index, + required int totalCnt, + required Future Function(int) getMore}) async { + if (index == (totalCnt - 1) && + index != 0 && + totalCnt % PAGINATION_SIZE == 0) { + Future.wait({getMore(index ~/ (PAGINATION_SIZE - 1))}); + } +}