Skip to content

Commit

Permalink
Merge pull request #283 from Mojacknong/feature/281
Browse files Browse the repository at this point in the history
[Merge] #281 -> dev
  • Loading branch information
geonheey authored Sep 28, 2024
2 parents da2dae3 + a9425e5 commit 35e2e2a
Show file tree
Hide file tree
Showing 13 changed files with 115 additions and 83 deletions.
13 changes: 7 additions & 6 deletions lib/common/tab_bar/farmclub_tab_bar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import 'package:farmus/common/content_empty.dart';
import 'package:farmus/common/tab_bar/primary_tab_bar.dart';
import 'package:farmus/model/my_farmclub/my_farmclub_info_model.dart';
import 'package:farmus/view/farmclub/component/farmclub_step.dart';
import 'package:farmus/view/farmclub/component/farmclub_step_tip.dart'; // 추가
import 'package:farmus/view/farmclub/component/farmclub_step_tip.dart';
import 'package:flutter/material.dart';

class FarmclubTabBar extends StatelessWidget {
Expand All @@ -18,12 +18,12 @@ class FarmclubTabBar extends StatelessWidget {
final List<StepModel> currentSteps = [steps[currentStepIndex]];

final List<StepModel> previousSteps =
(currentStepIndex > 0) ? steps.sublist(0, currentStepIndex) : [];
(currentStepIndex > 0) ? steps.sublist(0, currentStepIndex) : [];
final List<StepModel> nextSteps = (currentStepIndex < steps.length - 1)
? steps.sublist(currentStepIndex + 1)
: [];

Widget buildStepView(List<StepModel> stepModels, {bool addTip = false}) {
Widget buildStepView(List<StepModel> stepModels, {bool addTip = false, bool isLast = false}) {
return Padding(
padding: const EdgeInsets.all(16.0),
child: SingleChildScrollView(
Expand All @@ -37,20 +37,21 @@ class FarmclubTabBar extends StatelessWidget {
step: step,
farmclubInfo: farmclubInfo,
isButton: step.stepNum == currentStepIndex + 1,
isLast: farmclubInfo.steps.length == farmclubInfo.currentStep,
),
);
}),
if (addTip) FarmclubStepTip(tip: farmclubInfo.advice),

],
),
),
);
}

Widget buildTabView(List<StepModel> steps,
{bool isLast = false, bool addTip = false}) {
Widget buildTabView(List<StepModel> steps, {bool isLast = false, bool addTip = false}) {
return steps.isNotEmpty
? buildStepView(steps, addTip: addTip)
? buildStepView(steps, addTip: addTip, isLast: isLast)
: ContentEmpty(text: isLast ? '마지막 미션을 진행 중이에요!' : '아직 완료한 미션이 없어요');
}

Expand Down
21 changes: 4 additions & 17 deletions lib/data/network/my_farmclub_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

import '../../model/mission/mission_write_model.dart';
import '../../view/farmclub/farmclub_success_screen.dart';
import 'base_api_services.dart';

class MyFarmclubService {
Expand Down Expand Up @@ -109,21 +108,6 @@ class MyFarmclubService {
final Map<String, dynamic> responseData =
jsonDecode(utf8.decode(response.bodyBytes));

if (responseData['data']['isLastStep'] == true) {
try {
await myMissionSuccess(farmClubId);

WidgetsBinding.instance.addPostFrameCallback((_) {
Navigator.pushReplacement(
context,
MaterialPageRoute(builder: (context) => FarmclubSuccessScreen()),
);
});
} catch (e) {
throw Exception('미션 완료 후 성공 처리 실패');
}
}

return responseData['message'];
} else {
throw Exception('미션 완료 실패');
Expand All @@ -140,12 +124,15 @@ class MyFarmclubService {
final response = await apiClient.delete(url, body: body);

if (response.statusCode == 200) {
return utf8.decode(response.bodyBytes);
final responseBody = utf8.decode(response.bodyBytes);
return responseBody;
} else {
throw Exception('팜클럽 성공 실패');
}
}



Future<String> missionCommentAdd(int missionPostId, String content) async {
const url = '/api/farm-club/mission/comment';

Expand Down
2 changes: 1 addition & 1 deletion lib/model/home/my_veggie_list_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class MyVeggieListModel with _$MyVeggieListModel {
const factory MyVeggieListModel({
required int myVeggieId,
required String nickname,
required int userFarmClubId,
required int farmClubId,
}) = _MyVeggieListModel;

factory MyVeggieListModel.fromJson(Map<String, dynamic> json) =>
Expand Down
38 changes: 19 additions & 19 deletions lib/model/home/my_veggie_list_model.freezed.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ MyVeggieListModel _$MyVeggieListModelFromJson(Map<String, dynamic> json) {
mixin _$MyVeggieListModel {
int get myVeggieId => throw _privateConstructorUsedError;
String get nickname => throw _privateConstructorUsedError;
int get userFarmClubId => throw _privateConstructorUsedError;
int get farmClubId => throw _privateConstructorUsedError;

Map<String, dynamic> toJson() => throw _privateConstructorUsedError;
@JsonKey(ignore: true)
Expand All @@ -36,7 +36,7 @@ abstract class $MyVeggieListModelCopyWith<$Res> {
MyVeggieListModel value, $Res Function(MyVeggieListModel) then) =
_$MyVeggieListModelCopyWithImpl<$Res, MyVeggieListModel>;
@useResult
$Res call({int myVeggieId, String nickname, int userFarmClubId});
$Res call({int myVeggieId, String nickname, int farmClubId});
}

/// @nodoc
Expand All @@ -54,7 +54,7 @@ class _$MyVeggieListModelCopyWithImpl<$Res, $Val extends MyVeggieListModel>
$Res call({
Object? myVeggieId = null,
Object? nickname = null,
Object? userFarmClubId = null,
Object? farmClubId = null,
}) {
return _then(_value.copyWith(
myVeggieId: null == myVeggieId
Expand All @@ -65,9 +65,9 @@ class _$MyVeggieListModelCopyWithImpl<$Res, $Val extends MyVeggieListModel>
? _value.nickname
: nickname // ignore: cast_nullable_to_non_nullable
as String,
userFarmClubId: null == userFarmClubId
? _value.userFarmClubId
: userFarmClubId // ignore: cast_nullable_to_non_nullable
farmClubId: null == farmClubId
? _value.farmClubId
: farmClubId // ignore: cast_nullable_to_non_nullable
as int,
) as $Val);
}
Expand All @@ -81,7 +81,7 @@ abstract class _$$MyVeggieListModelImplCopyWith<$Res>
__$$MyVeggieListModelImplCopyWithImpl<$Res>;
@override
@useResult
$Res call({int myVeggieId, String nickname, int userFarmClubId});
$Res call({int myVeggieId, String nickname, int farmClubId});
}

/// @nodoc
Expand All @@ -97,7 +97,7 @@ class __$$MyVeggieListModelImplCopyWithImpl<$Res>
$Res call({
Object? myVeggieId = null,
Object? nickname = null,
Object? userFarmClubId = null,
Object? farmClubId = null,
}) {
return _then(_$MyVeggieListModelImpl(
myVeggieId: null == myVeggieId
Expand All @@ -108,9 +108,9 @@ class __$$MyVeggieListModelImplCopyWithImpl<$Res>
? _value.nickname
: nickname // ignore: cast_nullable_to_non_nullable
as String,
userFarmClubId: null == userFarmClubId
? _value.userFarmClubId
: userFarmClubId // ignore: cast_nullable_to_non_nullable
farmClubId: null == farmClubId
? _value.farmClubId
: farmClubId // ignore: cast_nullable_to_non_nullable
as int,
));
}
Expand All @@ -122,7 +122,7 @@ class _$MyVeggieListModelImpl implements _MyVeggieListModel {
const _$MyVeggieListModelImpl(
{required this.myVeggieId,
required this.nickname,
required this.userFarmClubId});
required this.farmClubId});

factory _$MyVeggieListModelImpl.fromJson(Map<String, dynamic> json) =>
_$$MyVeggieListModelImplFromJson(json);
Expand All @@ -132,11 +132,11 @@ class _$MyVeggieListModelImpl implements _MyVeggieListModel {
@override
final String nickname;
@override
final int userFarmClubId;
final int farmClubId;

@override
String toString() {
return 'MyVeggieListModel(myVeggieId: $myVeggieId, nickname: $nickname, userFarmClubId: $userFarmClubId)';
return 'MyVeggieListModel(myVeggieId: $myVeggieId, nickname: $nickname, farmClubId: $farmClubId)';
}

@override
Expand All @@ -148,14 +148,14 @@ class _$MyVeggieListModelImpl implements _MyVeggieListModel {
other.myVeggieId == myVeggieId) &&
(identical(other.nickname, nickname) ||
other.nickname == nickname) &&
(identical(other.userFarmClubId, userFarmClubId) ||
other.userFarmClubId == userFarmClubId));
(identical(other.farmClubId, farmClubId) ||
other.farmClubId == farmClubId));
}

@JsonKey(ignore: true)
@override
int get hashCode =>
Object.hash(runtimeType, myVeggieId, nickname, userFarmClubId);
Object.hash(runtimeType, myVeggieId, nickname, farmClubId);

@JsonKey(ignore: true)
@override
Expand All @@ -176,7 +176,7 @@ abstract class _MyVeggieListModel implements MyVeggieListModel {
const factory _MyVeggieListModel(
{required final int myVeggieId,
required final String nickname,
required final int userFarmClubId}) = _$MyVeggieListModelImpl;
required final int farmClubId}) = _$MyVeggieListModelImpl;

factory _MyVeggieListModel.fromJson(Map<String, dynamic> json) =
_$MyVeggieListModelImpl.fromJson;
Expand All @@ -186,7 +186,7 @@ abstract class _MyVeggieListModel implements MyVeggieListModel {
@override
String get nickname;
@override
int get userFarmClubId;
int get farmClubId;
@override
@JsonKey(ignore: true)
_$$MyVeggieListModelImplCopyWith<_$MyVeggieListModelImpl> get copyWith =>
Expand Down
4 changes: 2 additions & 2 deletions lib/model/home/my_veggie_list_model.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions lib/view/farmclub/component/farmclub_step.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@ class FarmclubStep extends ConsumerWidget {
required this.step,
required this.farmclubInfo,
required this.isButton,
required this.isLast,
});

final int wholeMember;
final StepModel step;
final MyFarmclubInfoModel farmclubInfo;
final bool isButton;
final bool isLast;

@override
Widget build(BuildContext context, WidgetRef ref) {
Expand Down Expand Up @@ -75,6 +77,7 @@ class FarmclubStep extends ConsumerWidget {
builder: (context) => MissionWriteScreen(
step: step,
farmClubId: farmclubInfo.farmClubId,
isLast: isLast,
),
),
);
Expand Down
14 changes: 12 additions & 2 deletions lib/view/farmclub/farmclub_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ class FarmclubScreen extends ConsumerWidget {
ref.watch(myFarmclubInfoModelProvider(selectedFarmclubId));
final AsyncValue<List<FarmclubOpenDiaryModel>> farmclubOpenDiary =
ref.watch(farmclubOpenDiaryModelProvider(selectedFarmclubId));

return Scaffold(
appBar: myFarmclub.when(
data: (farmclub) => FarmusLogoAppBar(
Expand Down Expand Up @@ -172,7 +171,18 @@ class FarmclubScreen extends ConsumerWidget {
);
},
loading: () => const Center(child: CircularProgressIndicator()),
error: (error, stack) => Center(child: Text('Error: $error')),
error: (error, stack) {
print('Error: $error');
return const Center(
child: SizedBox(
width: double.infinity,
child: ContentEmpty(
text: '이미 완료한 팜클럽입니다. 재실행해주세요',
padding: 45,
),
),
);
},
);
}
},
Expand Down
8 changes: 6 additions & 2 deletions lib/view/home/component/home_farmclub_mission.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class _HomeFarmclubMissionState extends ConsumerState<HomeFarmclubMission> {
orElse: () => veggieList.first,
);

if (selectedVeggie.userFarmClubId == -1) {
if (selectedVeggie.farmClubId == -1) {
return HomeNoneContainer(
title: '가입한 팜클럽이 없어요',
onPressed: () {
Expand All @@ -61,16 +61,20 @@ class _HomeFarmclubMissionState extends ConsumerState<HomeFarmclubMission> {
}

final AsyncValue<MyFarmclubInfoModel> myFarmclubInfo = ref.watch(
myFarmclubInfoModelProvider(selectedVeggie.userFarmClubId),
myFarmclubInfoModelProvider(selectedVeggie.farmClubId),
);

return myFarmclubInfo.when(

data: (farmclubInfo) => FarmclubStep(
wholeMember: farmclubInfo.wholeMemberCount,
step: farmclubInfo.steps[farmclubInfo.currentStep - 1],
farmclubInfo: farmclubInfo,
isButton: true,
isLast:farmclubInfo.steps.length == farmclubInfo.currentStep,

),

error: (error, stack) =>
Center(child: Text('Error: ${error.toString()}')),
loading: () => const Center(child: CircularProgressIndicator()),
Expand Down
6 changes: 3 additions & 3 deletions lib/view/home/home_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ class HomeScreen extends ConsumerWidget {
(veggie) => veggie.myVeggieId == selectedVegeId,
orElse: () => veggieListData.first,
);
if (selectedVeggie.userFarmClubId != -1) {
selectedFarmclubId = selectedVeggie.userFarmClubId;
if (selectedVeggie.farmClubId != -1) {
selectedFarmclubId = selectedVeggie.farmClubId;
}
}

Expand Down Expand Up @@ -144,7 +144,7 @@ class HomeScreen extends ConsumerWidget {
(veggie) => veggie.myVeggieId == selectedVegeId,
orElse: () => veggieListData.first,
);
if (selectedVeggie.userFarmClubId != -1) {
if (selectedVeggie.farmClubId != -1) {
ref.read(selectedFarmclubIdProvider.notifier).state =
selectedFarmclubId;
Navigator.push(
Expand Down
1 change: 1 addition & 0 deletions lib/view/mission_feed/component/mission_feed_tab_bar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ class _MissionFeedTabBarState extends ConsumerState<MissionFeedTabBar> {
MissionStepInfo(
step: step,
isButton: true,
isLast: true,
),
const SizedBox(height: 16.0),
stepFeeds.isEmpty
Expand Down
4 changes: 3 additions & 1 deletion lib/view/mission_write/component/mission_step_info.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ import '../../../common/button/round_gray_button.dart';

class MissionStepInfo extends ConsumerWidget {
const MissionStepInfo(
{super.key, required this.step, required this.isButton});
{super.key, required this.step, required this.isButton, required this.isLast});

final StepModel step;
final bool isButton;
final bool isLast;

@override
Widget build(BuildContext context, WidgetRef ref) {
Expand Down Expand Up @@ -57,6 +58,7 @@ class MissionStepInfo extends ConsumerWidget {
MaterialPageRoute(
builder: (builder) => MissionWriteScreen(
step: step,
isLast: isLast,
),
),
);
Expand Down
Loading

0 comments on commit 35e2e2a

Please sign in to comment.