Skip to content

Commit

Permalink
M3-154 Refactor : 클래스 이름, 구조 리팩토링
Browse files Browse the repository at this point in the history
  • Loading branch information
tkdals802 committed Jul 9, 2024
1 parent 2a8cba9 commit ccd3a87
Show file tree
Hide file tree
Showing 10 changed files with 137 additions and 211 deletions.
25 changes: 13 additions & 12 deletions lib/controllers/my_page_controller.dart
Original file line number Diff line number Diff line change
@@ -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<User> currentUserInfo = User().obs;
final Rx<UserPixelLog> userPixelLog = UserPixelLog().obs;
final Rx<UserPixelCount> userPixelCount = UserPixelCount().obs;

@override
Future<void> 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;
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
class UserPixelLog {
class UserPixelCount {
int? currentPixelCount;
int? accumulatePixelCount;

UserPixelLog({
UserPixelCount({
this.currentPixelCount,
this.accumulatePixelCount,
});

UserPixelLog.fromJson(Map<String, dynamic> json){
UserPixelCount.fromJson(Map<String, dynamic> json){
currentPixelCount = json['currentPixelCount'];
accumulatePixelCount = json['accumulatePixelCount'];
}
Expand Down
16 changes: 6 additions & 10 deletions lib/screens/my_page_screen.dart
Original file line number Diff line number Diff line change
@@ -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';

Expand All @@ -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),
Expand All @@ -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(),
],
),
Expand Down
1 change: 0 additions & 1 deletion lib/service/android_walking_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
10 changes: 5 additions & 5 deletions lib/service/user_service.dart
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -20,11 +20,11 @@ class UserService {
return User.fromJson(response.data['data']);
}

Future<UserPixelLog> getUserPixelLog() async {
Future<UserPixelCount> 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']);
}
}
51 changes: 51 additions & 0 deletions lib/widgets/my_page/dash_board.dart
Original file line number Diff line number Diff line change
@@ -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<MyPageController>();
WalkingController walkingController = Get.find<WalkingController>();

@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,
),
],
),
],
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<MyPageController>();
WalkingController walkingController = Get.find<WalkingController>();

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,
Expand Down
104 changes: 0 additions & 104 deletions lib/widgets/my_page/step_window.dart

This file was deleted.

5 changes: 1 addition & 4 deletions lib/widgets/my_page/today_goal_chart.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Loading

0 comments on commit ccd3a87

Please sign in to comment.