-
Notifications
You must be signed in to change notification settings - Fork 0
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
MentorIntroductionScreen 추가 #62
Open
sunnny619
wants to merge
1
commit into
main
Choose a base branch
from
add/MentorIntroduce
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
180 changes: 176 additions & 4 deletions
180
lib/features/mypage/mentor_introduce/mentor_introduce_screen.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,183 @@ | ||
import 'package:cogo/features/mypage/mentor_introduce/mentor_introduce_view_model.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:provider/provider.dart'; | ||
import 'package:cogo/common/widgets/widgets.dart'; | ||
|
||
class MentorIntroduceScreen extends StatelessWidget { | ||
const MentorIntroduceScreen({super.key}); | ||
class MentorIntroductionScreen extends StatelessWidget { | ||
const MentorIntroductionScreen({super.key}); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return const Scaffold( | ||
body: Center(child: Text('MentorIntroduce Screen')), | ||
return ChangeNotifierProvider( | ||
create: (_) => MentorIntroductionViewModel(), | ||
child: Scaffold( | ||
backgroundColor: Colors.white, | ||
body: SafeArea( | ||
child: SingleChildScrollView( | ||
child: Padding( | ||
padding: const EdgeInsets.all(16.0), | ||
child: Column( | ||
crossAxisAlignment: CrossAxisAlignment.start, | ||
children: [ | ||
Header( | ||
title: '멘토 자기소개', | ||
subtitle: '', | ||
onBackButtonPressed: () => Navigator.of(context).pop(), | ||
), | ||
const SizedBox(height: 10), | ||
Consumer<MentorIntroductionViewModel>( | ||
builder: (context, viewModel, child) { | ||
return Column( | ||
crossAxisAlignment: CrossAxisAlignment.start, | ||
children: [ | ||
// 제목 필드 | ||
_buildTitleTextField( | ||
viewModel, '제목', viewModel.introController), | ||
const SizedBox(height: 10), | ||
//자기소개 입력 | ||
_buildTextFieldWithCounter( | ||
viewModel, | ||
'자기소개를 입력해주세요', | ||
viewModel.question1Controller, | ||
viewModel.question1CharCount, | ||
200), | ||
const SizedBox(height: 10), | ||
// 첫 번째 질문 | ||
const Text( | ||
'어느 분야에서 멘토링 가능하신가요?', | ||
style: CogoTextStyle.body16, | ||
), | ||
const SizedBox(height: 10), | ||
_buildTextFieldWithCounter( | ||
viewModel, | ||
'답변을 입력해주세요', | ||
viewModel.question2Controller, | ||
viewModel.question2CharCount, | ||
200), | ||
const SizedBox(height: 20), | ||
// 두 번째 질문 | ||
const Text( | ||
'질문질문.... 자기소개 유도 질문...', | ||
style: CogoTextStyle.body16, | ||
), | ||
const SizedBox(height: 10), | ||
_buildTextFieldWithCounter( | ||
viewModel, | ||
'답변을 입력해주세요', | ||
viewModel.question3Controller, | ||
viewModel.question3CharCount, | ||
200), | ||
], | ||
); | ||
}, | ||
), | ||
const SizedBox(height: 30), | ||
// 저장하기 버튼 | ||
Center( | ||
child: SizedBox( | ||
width: double.infinity, | ||
height: 50, | ||
child: Consumer<MentorIntroductionViewModel>( | ||
builder: (context, viewModel, child) { | ||
return ElevatedButton( | ||
onPressed: viewModel.isFormValid | ||
? () => viewModel.saveIntroduction(context) | ||
: null, | ||
style: ElevatedButton.styleFrom( | ||
backgroundColor: viewModel.isFormValid | ||
? Colors.black | ||
: Colors.grey[300], | ||
foregroundColor: viewModel.isFormValid | ||
? Colors.white | ||
: Colors.black, | ||
textStyle: const TextStyle( | ||
fontFamily: 'PretendardMedium', | ||
fontSize: 18, | ||
), | ||
shape: RoundedRectangleBorder( | ||
borderRadius: BorderRadius.circular(20), | ||
), | ||
), | ||
child: const Text('저장하기'), | ||
); | ||
}, | ||
), | ||
), | ||
), | ||
], | ||
), | ||
), | ||
), | ||
), | ||
), | ||
); | ||
} | ||
|
||
/// widgets -> components -> basic textfield로 바꾸시면 됩니다 | ||
// 제목 필드를 따로 만드는 헬퍼 메서드 | ||
Widget _buildTitleTextField(MentorIntroductionViewModel viewModel, | ||
String hintText, TextEditingController controller) { | ||
return Container( | ||
height: 50, | ||
padding: const EdgeInsets.symmetric(horizontal: 16.0), | ||
decoration: BoxDecoration( | ||
color: const Color(0xFFF7F7F7), | ||
borderRadius: BorderRadius.circular(20), | ||
), | ||
child: TextField( | ||
controller: controller, | ||
maxLength: 50, | ||
maxLines: 1, // 한 줄로만 표현 | ||
decoration: InputDecoration( | ||
hintText: hintText, | ||
hintStyle: CogoTextStyle.unselectedText2, | ||
border: InputBorder.none, | ||
counterText: '', // 기본 카운터 숨기기 | ||
), | ||
onChanged: (text) { | ||
viewModel.updateCharCount(controller); // 글자 수 업데이트 | ||
}, | ||
), | ||
); | ||
} | ||
|
||
// 일반 TextField와 글자 수 카운터를 표시하는 헬퍼 메서드 | ||
Widget _buildTextFieldWithCounter( | ||
MentorIntroductionViewModel viewModel, | ||
String hintText, | ||
TextEditingController controller, | ||
int currentCount, | ||
int maxCount) { | ||
return Column( | ||
crossAxisAlignment: CrossAxisAlignment.end, | ||
children: [ | ||
Container( | ||
padding: const EdgeInsets.all(16.0), | ||
decoration: BoxDecoration( | ||
color: const Color(0xFFF7F7F7), | ||
borderRadius: BorderRadius.circular(20), | ||
), | ||
child: TextField( | ||
controller: controller, | ||
maxLength: maxCount, | ||
maxLines: 5, // 여러 줄 입력 가능 | ||
decoration: InputDecoration( | ||
hintText: hintText, | ||
hintStyle: CogoTextStyle.unselectedText2, | ||
border: InputBorder.none, | ||
counterText: '', // 기본 카운터 숨기기 | ||
), | ||
onChanged: (text) { | ||
viewModel.updateCharCount(controller); // 글자 수 업데이트 | ||
}, | ||
), | ||
), | ||
const SizedBox(height: 5), | ||
Text( | ||
'$currentCount/$maxCount', // 실시간으로 글자 수를 표시 | ||
style: CogoTextStyle.unselectedText2, | ||
), | ||
], | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import 'package:flutter/material.dart'; | ||
|
||
class MentorIntroductionViewModel extends ChangeNotifier { | ||
// TextEditingController로 각 필드 관리 | ||
final TextEditingController introController = TextEditingController(); | ||
final TextEditingController question1Controller = TextEditingController(); | ||
final TextEditingController question2Controller = TextEditingController(); | ||
final TextEditingController question3Controller = TextEditingController(); | ||
|
||
bool isFormValid = false; | ||
|
||
// 각 텍스트 필드의 글자 수를 계산 | ||
int get introCharCount => introController.text.length; | ||
int get question1CharCount => question1Controller.text.length; | ||
int get question2CharCount => question2Controller.text.length; | ||
int get question3CharCount => question3Controller.text.length; | ||
|
||
MentorIntroductionViewModel() { | ||
// 각 컨트롤러에 리스너를 추가하여 값이 변경될 때마다 상태를 확인 | ||
introController.addListener(_validateForm); | ||
question1Controller.addListener(_validateForm); | ||
question2Controller.addListener(_validateForm); | ||
question3Controller.addListener(_validateForm); | ||
} | ||
|
||
// 텍스트가 변경될 때마다 유효성 검사 수행 | ||
void _validateForm() { | ||
isFormValid = introController.text.isNotEmpty && | ||
question1Controller.text.isNotEmpty && | ||
question2Controller.text.isNotEmpty && | ||
question3Controller.text.isNotEmpty; | ||
notifyListeners(); | ||
} | ||
|
||
// 글자 수 업데이트 | ||
void updateCharCount(TextEditingController controller) { | ||
notifyListeners(); // 글자 수 변화를 알림 | ||
} | ||
|
||
// 데이터를 저장하는 함수 | ||
void saveIntroduction(BuildContext context) { | ||
//TODO : 데이터 저장 로직 구현 | ||
Navigator.of(context).pop(); // 저장 후 화면 종료 | ||
} | ||
|
||
// ViewModel이 제거될 때 Controller도 함께 해제 | ||
@override | ||
void dispose() { | ||
introController.dispose(); | ||
question1Controller.dispose(); | ||
question2Controller.dispose(); | ||
question3Controller.dispose(); | ||
super.dispose(); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
compose에서는 뷰모델을 통째로 넘겨주는게 아니라 뷰모델의 함수만 넘겨주는게 정석이긴한데, 플러터에서도 그런지는 모르겠어요! 해당 위젯이 뷰모델 전체를 알아야할 필요성은 없어보이긴 합니당