From ccd3a876be20c43b4925d42f6f7cd64957f482c9 Mon Sep 17 00:00:00 2001 From: cha-imag <100341870+tkdals802@users.noreply.github.com> Date: Tue, 9 Jul 2024 17:28:31 +0900 Subject: [PATCH] =?UTF-8?q?M3-154=20Refactor=20:=20=ED=81=B4=EB=9E=98?= =?UTF-8?q?=EC=8A=A4=20=EC=9D=B4=EB=A6=84,=20=EA=B5=AC=EC=A1=B0=20?= =?UTF-8?q?=EB=A6=AC=ED=8C=A9=ED=86=A0=EB=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/controllers/my_page_controller.dart | 25 +++-- ...r_pixel_log.dart => user_pixel_count.dart} | 6 +- lib/screens/my_page_screen.dart | 16 +-- lib/service/android_walking_service.dart | 1 - lib/service/user_service.dart | 10 +- lib/widgets/my_page/dash_board.dart | 51 +++++++++ ...step_count.dart => dash_board_widget.dart} | 39 ++----- lib/widgets/my_page/step_window.dart | 104 ------------------ lib/widgets/my_page/today_goal_chart.dart | 5 +- lib/widgets/my_page/user_info.dart | 91 +++++++-------- 10 files changed, 137 insertions(+), 211 deletions(-) rename lib/models/{user_pixel_log.dart => user_pixel_count.dart} (71%) create mode 100644 lib/widgets/my_page/dash_board.dart rename lib/widgets/my_page/{display_pixel_step_count.dart => dash_board_widget.dart} (53%) delete mode 100644 lib/widgets/my_page/step_window.dart diff --git a/lib/controllers/my_page_controller.dart b/lib/controllers/my_page_controller.dart index 59f4b0a1..126cb6bc 100644 --- a/lib/controllers/my_page_controller.dart +++ b/lib/controllers/my_page_controller.dart @@ -1,40 +1,41 @@ import 'package:get/get.dart'; import '../models/user.dart'; -import '../models/user_pixel_log.dart'; +import '../models/user_pixel_count.dart'; import '../service/user_service.dart'; class MyPageController extends GetxController { final UserService userService = UserService(); final Rx currentUserInfo = User().obs; - final Rx userPixelLog = UserPixelLog().obs; + final Rx userPixelCount = UserPixelCount().obs; @override Future onInit() async { + super.onInit(); User userInfo = await userService.getCurrentUserInfo(); - UserPixelLog userPixelLogInfo = await userService.getUserPixelLog(); + UserPixelCount userPixelLogInfo = await userService.getUserPixelCount(); currentUserInfo.value = userInfo; - userPixelLog.value = userPixelLogInfo; - super.onInit(); + userPixelCount.value = userPixelLogInfo; + print('userinfo info ${userInfo}'); } getProfileImageURL() { return currentUserInfo.value.profileImageUrl; } - getCurrentUserNickname() { - return currentUserInfo.value.nickname; + String getCurrentUserNickname() { + return currentUserInfo.value.nickname ?? "-"; } - getCurrentUserCommunityName() { + String getCurrentUserCommunityName() { return currentUserInfo.value.communityName ?? "-"; } - getCurrentUserPixel(){ - return userPixelLog.value.currentPixelCount; + int getCurrentUserPixel(){ + return userPixelCount.value.currentPixelCount ?? 0; } - getAccumulateUserPixel(){ - return userPixelLog.value.accumulatePixelCount; + int getAccumulateUserPixel(){ + return userPixelCount.value.accumulatePixelCount ?? 0; } } diff --git a/lib/models/user_pixel_log.dart b/lib/models/user_pixel_count.dart similarity index 71% rename from lib/models/user_pixel_log.dart rename to lib/models/user_pixel_count.dart index 15a7aef8..3b87de11 100644 --- a/lib/models/user_pixel_log.dart +++ b/lib/models/user_pixel_count.dart @@ -1,13 +1,13 @@ -class UserPixelLog { +class UserPixelCount { int? currentPixelCount; int? accumulatePixelCount; - UserPixelLog({ + UserPixelCount({ this.currentPixelCount, this.accumulatePixelCount, }); - UserPixelLog.fromJson(Map json){ + UserPixelCount.fromJson(Map json){ currentPixelCount = json['currentPixelCount']; accumulatePixelCount = json['accumulatePixelCount']; } diff --git a/lib/screens/my_page_screen.dart b/lib/screens/my_page_screen.dart index 48b67e03..d627aad4 100644 --- a/lib/screens/my_page_screen.dart +++ b/lib/screens/my_page_screen.dart @@ -1,9 +1,10 @@ import 'package:flutter/material.dart'; import 'package:get/get.dart'; +import '../controllers/my_page_controller.dart'; import '../controllers/walking_controller.dart'; import '../widgets/my_page/step_bar_chart.dart'; -import '../widgets/my_page/step_window.dart'; +import '../widgets/my_page/dash_board.dart'; import '../widgets/my_page/today_goal_chart.dart'; import '../widgets/my_page/user_info.dart'; @@ -12,7 +13,8 @@ class MyPageScreen extends StatelessWidget { @override Widget build(BuildContext context) { - final WalkingController walkController = Get.put(WalkingController()); + Get.put(WalkingController()); + Get.put(MyPageController()); return Padding( padding: const EdgeInsets.all(8.0), @@ -22,17 +24,11 @@ class MyPageScreen extends StatelessWidget { Container( height: 10, ), - StepWindow(), - Container( + DashBoard(), + SizedBox( height: 10, ), TodayGoalChart(), - TextButton( - onPressed: () { - walkController.updateCurrentStep(); - }, - child: const Text('업데이트'), - ), StepBarChart(), ], ), diff --git a/lib/service/android_walking_service.dart b/lib/service/android_walking_service.dart index 3ae3dd46..5fd9469e 100644 --- a/lib/service/android_walking_service.dart +++ b/lib/service/android_walking_service.dart @@ -6,7 +6,6 @@ import 'package:flutter_foreground_task/flutter_foreground_task.dart'; import '../utils/android_notification.dart'; import '../utils/walking_service.dart'; -//ToDo : 안드로이드 서비스 실제로 구현하기 class AndroidWalkingService implements WalkingService { ReceivePort? _receivePort; int currentSteps = 0; diff --git a/lib/service/user_service.dart b/lib/service/user_service.dart index 21cc2790..8bef2d1d 100644 --- a/lib/service/user_service.dart +++ b/lib/service/user_service.dart @@ -1,7 +1,7 @@ import 'package:dio/dio.dart'; import '../models/user.dart'; -import '../models/user_pixel_log.dart'; +import '../models/user_pixel_count.dart'; import '../utils/dio_service.dart'; class UserService { @@ -20,11 +20,11 @@ class UserService { return User.fromJson(response.data['data']); } - Future getUserPixelLog() async { + Future getUserPixelCount() async { var response = await dio.get( - '/count', - queryParameters: {'user-id': userId}, + '/pixels/count', + queryParameters: {"user-id": userId}, ); - return UserPixelLog.fromJson(response.data['data']); + return UserPixelCount.fromJson(response.data['data']); } } diff --git a/lib/widgets/my_page/dash_board.dart b/lib/widgets/my_page/dash_board.dart new file mode 100644 index 00000000..555f3712 --- /dev/null +++ b/lib/widgets/my_page/dash_board.dart @@ -0,0 +1,51 @@ +import 'package:flutter/material.dart'; +import 'package:get/get.dart'; +import 'package:get/get_core/src/get_main.dart'; + +import '../../controllers/my_page_controller.dart'; +import '../../controllers/walking_controller.dart'; +import 'dash_board_widget.dart'; + +class DashBoard extends StatelessWidget { + DashBoard({ + super.key, + }); + + MyPageController myPageController = Get.find(); + WalkingController walkingController = Get.find(); + + @override + Widget build(BuildContext context) { + return Stack( + alignment: Alignment.center, + children: [ + Container( + padding: const EdgeInsets.all(10.0), + height: 150, + decoration: BoxDecoration( + color: Color(0xFFD9D9D9), + borderRadius: BorderRadius.circular(10), + ), + ), + Row( + mainAxisAlignment: MainAxisAlignment.spaceEvenly, + children: [ + DashBoardWidget( + textValue: "현재 픽셀수", + iconImageUrl: "currentTile.png", + countValue: myPageController.getCurrentUserPixel().obs,), + DashBoardWidget( + textValue: "누적 픽셀수", + iconImageUrl: "allTile.png", + countValue: myPageController.getAccumulateUserPixel().obs,), + DashBoardWidget( + textValue: "걸음수", + iconImageUrl: "stepIcon.png", + countValue: walkingController.currentStep, + ), + ], + ), + ], + ); + } +} diff --git a/lib/widgets/my_page/display_pixel_step_count.dart b/lib/widgets/my_page/dash_board_widget.dart similarity index 53% rename from lib/widgets/my_page/display_pixel_step_count.dart rename to lib/widgets/my_page/dash_board_widget.dart index df8ba7a3..80500ae1 100644 --- a/lib/widgets/my_page/display_pixel_step_count.dart +++ b/lib/widgets/my_page/dash_board_widget.dart @@ -4,43 +4,26 @@ import 'package:get/get.dart'; import '../../controllers/my_page_controller.dart'; import '../../controllers/walking_controller.dart'; -class DisplayPixelStepCount extends StatelessWidget { - final String check; +class DashBoardWidget extends StatelessWidget { + final String textValue; + final String iconImageUrl; + RxInt countValue = 0.obs; - DisplayPixelStepCount({ + DashBoardWidget({ super.key, - required this.check, + required this.textValue, + required this.iconImageUrl, + required this.countValue, }); MyPageController myPageController = Get.find(); WalkingController walkingController = Get.find(); - RxString textValue = '-'.obs; - RxInt countValue = 0.obs; - RxString iconImageUrl = '-'.obs; - - checkValue(check){ - switch(check){ - case '현재': - textValue.value = '현재 픽셀수'; - countValue.value = myPageController.getCurrentUserPixel(); - iconImageUrl.value = 'currentTile.png'; - break; - case '누적': - textValue.value = '누적 픽셀수'; - countValue.value = myPageController.getAccumulateUserPixel(); - iconImageUrl.value = 'allTile.png'; - break; - case '걸음수': - textValue.value = '걸음수'; - countValue = walkingController.currentStep; - iconImageUrl.value = 'stepIcon.png'; - break; - } - } + // RxString textValue = '-'.obs; + // RxInt countValue = 0.obs; + // RxString iconImageUrl = '-'.obs; @override Widget build(BuildContext context) { - checkValue(check); return Container( width: 100, height: 140, diff --git a/lib/widgets/my_page/step_window.dart b/lib/widgets/my_page/step_window.dart deleted file mode 100644 index 65b3cd82..00000000 --- a/lib/widgets/my_page/step_window.dart +++ /dev/null @@ -1,104 +0,0 @@ -import 'package:flutter/material.dart'; -import 'package:get/get.dart'; - -import '../../controllers/my_page_controller.dart'; -import '../../controllers/walking_controller.dart'; - -class StepWindow extends StatelessWidget { - const StepWindow({super.key}); - - @override - Widget build(BuildContext context) { - final WalkingController walkController = Get.put(WalkingController()); - final MyPageController myPageController = Get.put(MyPageController()); - - return Stack( - alignment: Alignment.center, - children: [ - Container( - padding: const EdgeInsets.all(10.0), - height: 150, - decoration: BoxDecoration( - color: Color(0xFFD9D9D9), - borderRadius: BorderRadius.circular(10), - ), - ), - Row( - mainAxisAlignment: MainAxisAlignment.spaceEvenly, - children: [ - Container( - width: 120, - height: 130, - decoration: BoxDecoration( - color: Colors.white, - borderRadius: BorderRadius.circular(10), - ), - child: Column( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - Text('현재 픽셀수'), - Image.asset( - 'assets/currentTile.png', - width: 80, - height: 80, - ), - Obx( - () => Text( - myPageController.getCurrentUserPixel().toString(), - ), - ), - ], - ), - ), - Container( - width: 120, - height: 130, - decoration: BoxDecoration( - color: Colors.white, - borderRadius: BorderRadius.circular(10), - ), - child: Column( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - Text('누적 픽셀수'), - Image.asset( - 'assets/allTile.png', - width: 80, - height: 80, - ), - Obx( - () => Text( - myPageController.getAccumulateUserPixel().toString(), - ), - ), - ], - ), - ), - Container( - width: 120, - height: 130, - decoration: BoxDecoration( - color: Colors.white, - borderRadius: BorderRadius.circular(10), - ), - child: Column( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - Text('걸음 수'), - Image.asset( - 'assets/stepIcon.png', - width: 80, - height: 80, - ), - Obx( - () => Text('${walkController.currentStep.value}'), - ), - ], - ), - ), - ], - ), - ], - ); - } -} diff --git a/lib/widgets/my_page/today_goal_chart.dart b/lib/widgets/my_page/today_goal_chart.dart index 01e0cdfe..486f6665 100644 --- a/lib/widgets/my_page/today_goal_chart.dart +++ b/lib/widgets/my_page/today_goal_chart.dart @@ -8,10 +8,7 @@ class TodayGoalChart extends StatelessWidget { @override Widget build(BuildContext context) { - final WalkingController walkingController = Get.put( - WalkingController(), - ); - + WalkingController walkingController = Get.put(WalkingController()); return Column( children: [ Stack( diff --git a/lib/widgets/my_page/user_info.dart b/lib/widgets/my_page/user_info.dart index fb2fa31a..e825c098 100644 --- a/lib/widgets/my_page/user_info.dart +++ b/lib/widgets/my_page/user_info.dart @@ -14,51 +14,54 @@ class UserInfo extends StatelessWidget { // TODO: 개인정보 수정 페이지로 넘어가게 구현 }, child: Ink( - decoration: const BoxDecoration( - color: Color(0xFFD9D9D9), - borderRadius: BorderRadius.all(Radius.circular(8)), - ), - child: Padding( - padding: const EdgeInsets.all(10.0), - child: Obx( - () => Row( - children: [ - ClipOval( - child: myPageController.getProfileImageURL() != null - ? Image.network( - myPageController - .getProfileImageURL() - .profileImageUrl!, - width: 80, - height: 80, - fit: BoxFit.cover, - ) - : Image.asset( - 'assets/default_profile_image.png', - width: 80, - height: 80, - ), - ), - SizedBox( - width: 30, - ), - Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Text( - '그룹명',// myPageController.getCurrentUserNickname(), - style: TextStyle(fontSize: 25), - ), - Text('닉네임',//myPageController.getCurrentUserCommunityName(), - style: TextStyle(fontSize: 20),), - ], - ), - Spacer(), - Icon(Icons.arrow_forward_ios), - ], - ), + decoration: const BoxDecoration( + color: Color(0xFFD9D9D9), + borderRadius: BorderRadius.all(Radius.circular(8)), + ), + child: Padding( + padding: const EdgeInsets.all(10.0), + child: Obx( + () => Row( + children: [ + ClipOval( + child: myPageController.getProfileImageURL() != null + ? Image.network( + myPageController + .getProfileImageURL() + .profileImageUrl!, + width: 80, + height: 80, + fit: BoxFit.cover, + ) + : Image.asset( + 'assets/default_profile_image.png', + width: 80, + height: 80, + ), + ), + SizedBox( + width: 30, + ), + Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text( + myPageController.getCurrentUserNickname(), + style: TextStyle(fontSize: 25), + ), + Text( + myPageController.getCurrentUserCommunityName(), + style: TextStyle(fontSize: 20), + ), + ], + ), + Spacer(), + Icon(Icons.arrow_forward_ios), + ], ), - ),), + ), + ), + ), ); } }