Skip to content

Commit

Permalink
refactor:#35 view listview 호출 메소드 분리 + 조건 수정
Browse files Browse the repository at this point in the history
맨끝에서만 호출, currentPage 변경
api, controller 메소드 통일 필요
  • Loading branch information
kimwest00 committed Nov 24, 2023
1 parent 87717ff commit 825b7c6
Show file tree
Hide file tree
Showing 26 changed files with 145 additions and 141 deletions.
11 changes: 5 additions & 6 deletions lib/modules/alarm/controller/alarm_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,17 @@ class AlarmController extends GetxController {
static AlarmController get to => Get.find();
RxList<Notification> notifcationList = <Notification>[].obs;

Future<void> getMoreNotification({required int index}) async {
Future<void> 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());
}
Expand Down
12 changes: 5 additions & 7 deletions lib/modules/alarm/view/alarm_view.dart
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -20,13 +21,10 @@ class AlarmScreen extends GetView<AlarmController> {
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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@ class BurningMatchController extends GetxController {
///<h2> Listview builder에서 호출하는 pagination 추가 호출 함수 </h2>
///* 총 데이터 수와 비교하여, 페이지를 더 늘릴수있다면 api 호출, 그렇지 않다면 호출 X
Future<void> 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));
}
Expand Down
9 changes: 2 additions & 7 deletions lib/modules/buring_match/view/burning_match_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -82,13 +83,7 @@ class BurningMatchScreen extends GetView<BurningMatchController> {
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,
Expand Down
4 changes: 1 addition & 3 deletions lib/modules/donate/controller/donate_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@ class DonateController extends GetxController {

///pagination 함수
Future<void> 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));
}
Expand Down
52 changes: 29 additions & 23 deletions lib/modules/donate/view/donate_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -29,8 +30,8 @@ class DonateScreen extends GetView<DonateController> {
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(
Expand All @@ -56,6 +57,7 @@ class DonateScreen extends GetView<DonateController> {
],
),
),

///*2.프로젝트 카테고리
SizedBox(
height: 76.h,
Expand Down Expand Up @@ -98,29 +100,33 @@ class DonateScreen extends GetView<DonateController> {
}),
),
),

///*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(),
),
],
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class DonationSearchController extends GetxController {

///* 추천 검색어 리스트
RxList<String> recommendSearchList = List.generate(10, (index) => "").obs;

RxString currentSearchText = "".obs;
///▼ 입력을 시작하고, 아무 action이 없을시
///자동으로 검색되는 기능을 위한 변수
Expand Down Expand Up @@ -62,18 +62,17 @@ class DonationSearchController extends GetxController {
totalSearchLength.value = ProjectApi.project.totalCnt;

searchStatus.value = SEARCH_STATUS.SEARCH;
currentSearchText.value = content;
}

///* 검색 결과 api에대한 pagination을 처리하는 함수
Future<void> getMoreSearchList(
{required String content, required int index}) async {
if (!(ProjectApi.project.totalCnt ~/ PAGINATION_SIZE < index) &&
!ProjectApi.project.isLast) {
Future<void> 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 ,
));
}
}
Expand Down
11 changes: 2 additions & 9 deletions lib/modules/donation_search/view/donation_search_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -110,15 +111,7 @@ class DonationSearchScreen extends GetView<DonationSearchController> {
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(
Expand Down
9 changes: 4 additions & 5 deletions lib/modules/event/controller/event_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,14 @@ class EventController extends GetxController {
RxList<Event> eventList = <Event>[].obs;

///* pagination 함수
Future<void> getMoreNotice({required int index}) async {
if (!(EventApi.event.totalCnt ~/ PAGINATION_SIZE < index) &&
!EventApi.event.isLast) {
EventApi.event.currentpage = index;
Future<void> 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());
}
Expand Down
13 changes: 6 additions & 7 deletions lib/modules/event/view/event_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -53,13 +54,11 @@ class EventScreen extends GetView<EventController> {
: 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]);
Expand Down
3 changes: 1 addition & 2 deletions lib/modules/home/controller/home_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

Expand Down
20 changes: 11 additions & 9 deletions lib/modules/home/view/home_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -129,13 +130,12 @@ class HomeScreen extends GetView<HomeController> {
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: [
Expand Down Expand Up @@ -165,6 +165,7 @@ class HomeScreen extends GetView<HomeController> {
),
);
}

//TODO: kakao -> app routing 테스트 이전
Widget shareChip({required String imgUrl, required int projectId}) {
return GestureDetector(
Expand All @@ -175,7 +176,7 @@ class HomeScreen extends GetView<HomeController> {
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(
Expand All @@ -187,7 +188,8 @@ class HomeScreen extends GetView<HomeController> {
),
Text(
"공유하기",
style: AppTextStyles.L1Medium12.copyWith(color: AppColors.grey5),
style:
AppTextStyles.L1Medium12.copyWith(color: AppColors.grey5),
)
],
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,10 @@ class LikeProjectController extends GetxController {
RxList<TodayProject> projectList = <TodayProject>[].obs;

///* 프로젝트 pagination
Future<void> getMoreProject({required int index}) async {
Future<void> 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,
Expand Down
11 changes: 5 additions & 6 deletions lib/modules/like_project/view/like_project_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -22,12 +23,10 @@ class LikeProjectScreen extends GetView<LikeProjectController> {
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);
},
Expand Down
Loading

0 comments on commit 825b7c6

Please sign in to comment.