Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

M3-334 그룹 메인 페이지 구현의 기능 구현 #94

Merged
merged 8 commits into from
Sep 6, 2024
52 changes: 39 additions & 13 deletions lib/controllers/community_controller.dart
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
import 'package:get/get.dart';

import '../models/community.dart';
import '../models/ranking.dart';
import '../service/community_service.dart';
import 'my_page_controller.dart';

class CommunityController extends GetxController {
final CommunityService communityService = CommunityService();
final RxString name = "".obs;
final RxString imageUrl = "".obs;

final RxInt communityId = 0.obs;
final RxInt memberCount = 0.obs;
final RxInt communityColor = 0.obs;
final RxInt communityRanking = 0.obs;
final RxInt currentPixelCount = 0.obs;
final RxInt accumulatePixelCount = 0.obs;
final RxInt maxPixelCount = 0.obs;
final RxInt maxRankingCount = 0.obs;
final RxInt maxRanking = 0.obs;
final RxBool isJoin = true.obs;
final RxBool isLoading = true.obs;

final RxList members = [
Ranking(userId: 1, rank: 1, currentPixelCount: 123, nickname: "test1"),
Expand All @@ -23,16 +28,37 @@ class CommunityController extends GetxController {
Ranking(userId: 1, rank: 5, currentPixelCount: 123, nickname: "test5"),
].obs;

init(int groupId) {
name.value = "세종대학교";
imageUrl.value =
"https://ground-flip-prod-storage-resized.s3.ap-northeast-2.amazonaws.com/resized-static/42166cf0-b557-42a1-a1fb-d04472ea0ac1%23%23%23622.jpg";
memberCount.value = 3;
communityColor.value = 0xFF0DF69E;
communityRanking.value = 534;
currentPixelCount.value = 124;
accumulatePixelCount.value = 11394;
maxPixelCount.value = 945;
maxRankingCount.value = 53;
init() async {
MyPageController myPageController = Get.find<MyPageController>();
if (myPageController.currentUserInfo.value.communityId == null) {
isJoin.value = false;
} else {
await updateCommunityInfo();
}
}

updateCommunityInfo() async {
isJoin.value = true;
communityId.value =
Get.find<MyPageController>().currentUserInfo.value.communityId!;
Community community =
await communityService.getCommunityInfo(communityId.value);
name.value = community.name;
imageUrl.value = community.backgroundImageUrl;
memberCount.value = community.memberCount;
communityColor.value = community.communityColor;
communityRanking.value = community.communityRanking;
currentPixelCount.value = community.currentPixelCount;
accumulatePixelCount.value = community.accumulatePixelCount;
maxPixelCount.value = community.maxPixelCount;
maxRanking.value = community.maxRanking;
isLoading.value = false;
}

quitCommunity() {
// ToDo : 그룹 탈퇴 구현
MyPageController myPageController = Get.find<MyPageController>();
myPageController.updateUserInfo();
isJoin.value = false;
}
}
51 changes: 51 additions & 0 deletions lib/controllers/community_info_controller.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import 'package:get/get.dart';

import '../models/community.dart';
import '../models/ranking.dart';
import '../service/community_service.dart';
import 'community_controller.dart';
import 'my_page_controller.dart';

class CommunityInfoController extends GetxController {
final CommunityService communityService = CommunityService();
final RxString name = "".obs;
final RxString imageUrl = "".obs;
final RxInt memberCount = 0.obs;
final RxInt communityColor = 0.obs;
final RxInt communityRanking = 0.obs;
final RxInt currentPixelCount = 0.obs;
final RxInt accumulatePixelCount = 0.obs;
final RxInt maxPixelCount = 0.obs;
final RxInt maxRanking = 0.obs;
final RxBool isLoading = true.obs;

final RxList members = [
Ranking(userId: 1, rank: 1, currentPixelCount: 123, nickname: "test1"),
Ranking(userId: 1, rank: 2, currentPixelCount: 123, nickname: "test2"),
Ranking(userId: 1, rank: 3, currentPixelCount: 123, nickname: "test3"),
Ranking(userId: 1, rank: 4, currentPixelCount: 123, nickname: "test4"),
Ranking(userId: 1, rank: 5, currentPixelCount: 123, nickname: "test5"),
].obs;

init(int communityId) async {
Community community = await communityService.getCommunityInfo(communityId);
name.value = community.name;
imageUrl.value = community.backgroundImageUrl;
memberCount.value = community.memberCount;
communityColor.value = community.communityColor;
communityRanking.value = community.communityRanking;
currentPixelCount.value = community.currentPixelCount;
accumulatePixelCount.value = community.accumulatePixelCount;
maxPixelCount.value = community.maxPixelCount;
maxRanking.value = community.maxRanking;
isLoading.value = false;
}

signUpCommunity() async {
// ToDo : 그룹 가입 구현
MyPageController myPageController = Get.find<MyPageController>();
CommunityController communityController = Get.find<CommunityController>();
await myPageController.updateUserInfo();
communityController.updateCommunityInfo();
}
}
7 changes: 3 additions & 4 deletions lib/controllers/navigation_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,14 @@ class NavigationController extends GetxController {
final RankingController rankingController = Get.find<RankingController>();
final MapController mapController = Get.find<MapController>();
final RxInt selectedIndex = 0.obs;

static List<Widget> tabPages = <Widget>[
const MapScreen(),
const RankingScreen(),
const CommunityScreen(
groupId: 1,
isTap: true,
),
const CommunityScreen(),
const MyPageScreen(),
];

static List<Widget> appBars = <Widget>[
const MapAppBar(),
const RankingAppBar(),
Expand Down
39 changes: 39 additions & 0 deletions lib/models/community.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
class Community {
int communityRanking;
String name;
int communityColor;
String backgroundImageUrl;
int memberCount;
int currentPixelCount;
int accumulatePixelCount;
int maxPixelCount;
int maxRanking;

Community({
required this.communityRanking,
required this.name,
required this.communityColor,
required this.backgroundImageUrl,
required this.memberCount,
required this.currentPixelCount,
required this.accumulatePixelCount,
required this.maxPixelCount,
required this.maxRanking,
});

factory Community.fromJson(Map<String, dynamic> json) {
return Community(
communityRanking: json['communityRanking'],
name: json['name'],
communityColor: json['communityColor'] is String
? int.parse(json['communityColor'], radix: 16)
: json['communityColor'],
backgroundImageUrl: json['backgroundImageUrl'],
memberCount: json['memberCount'],
currentPixelCount: json['currentPixelCount'],
accumulatePixelCount: json['accumulatePixelCount'],
maxPixelCount: json['maxPixelCount'],
maxRanking: json['maxRanking'],
);
}
}
139 changes: 139 additions & 0 deletions lib/screens/community_info_screen.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
import 'package:flutter/material.dart';
import 'package:flutter_svg/svg.dart';
import 'package:get/get.dart';

import '../constants/app_colors.dart';
import '../controllers/community_info_controller.dart';
import '../widgets/community/community_action_button.dart';
import '../widgets/community/community_image.dart';
import '../widgets/community/community_info.dart';
import '../widgets/community/community_record.dart';
import '../widgets/community/member/member_list.dart';

class CommunityInfoScreen extends StatelessWidget {
final int groupId;

const CommunityInfoScreen({
super.key,
required this.groupId,
});

@override
Widget build(BuildContext context) {
final CommunityInfoController communityInfoController =
Get.put(CommunityInfoController());
communityInfoController.init(groupId);

return Scaffold(
backgroundColor: Colors.black,
body: Obx(() {
if (communityInfoController.isLoading.value) {
return const Center(
child: CircularProgressIndicator(
color: AppColors.primary,
),
);
} else {
return CustomScrollView(
slivers: [
SliverAppBar(
expandedHeight: 350.0,
floating: false,
pinned: true,
iconTheme: IconThemeData(
color: Colors.white,
),
leading: IconButton(
icon: Icon(Icons.arrow_back_ios),
onPressed: () {
Get.back();
},
),
actions: [
IconButton(
icon: SvgPicture.asset(
'assets/images/share_icon.svg',
width: 20,
),
onPressed: () {},
),
],
backgroundColor: AppColors.background,
flexibleSpace: LayoutBuilder(
builder: (BuildContext context, BoxConstraints constraints) {
var top = constraints.biggest.height;
return FlexibleSpaceBar(
title: top <= 120
? Text(
communityInfoController.name.value,
style: TextStyle(
color: Colors.white,
fontWeight: FontWeight.bold,
),
)
: Align(
alignment: Alignment.bottomLeft,
child: Padding(
padding: const EdgeInsets.symmetric(
horizontal: 10.0,
),
child: Text(
communityInfoController.name.value,
style: TextStyle(
color: Colors.white,
fontWeight: FontWeight.bold,
fontSize: 20,
),
),
),
),
background: CommunityImage(
imageUrl: communityInfoController.imageUrl.value,
),
collapseMode: CollapseMode.parallax,
);
},
),
),
SliverToBoxAdapter(
child: Padding(
padding: EdgeInsets.all(10),
child: Column(
children: [
CommunityInfo(
memberCount: communityInfoController.memberCount,
communityColor: communityInfoController.communityColor,
weeklyRanking: communityInfoController.communityRanking,
),
SizedBox(
height: 20,
),
CommunityRecord(
currentPixelCount:
communityInfoController.currentPixelCount,
accumulatePixelCount:
communityInfoController.accumulatePixelCount,
maxPixelCount: communityInfoController.maxPixelCount,
maxRankingCount: communityInfoController.maxRanking,
),
SizedBox(
height: 20,
),
MemberList(members: communityInfoController.members),
SizedBox(
height: 20,
),
SignUpCommunityButton(
onTap: communityInfoController.signUpCommunity,
),
],
),
),
),
],
);
}
}),
);
}
}
Loading