Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | |||||
3 | 4 | 5 | 6 | 7 | 8 | 9 |
10 | 11 | 12 | 13 | 14 | 15 | 16 |
17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 | 25 | 26 | 27 | 28 | 29 | 30 |
31 |
Tags
- 플러터 #Flutter #파이어베이스 #firebase #firestore #파이어스토어
- AAB
- 유니티게임 #상점만들기 #뽑기구현 #케이디리듬게임
- 복권번호예측 #Flutter #플러터 #Provider
- 복권번호예측기 #Flutter #adMob #광고배너 #리워드형광고
- Flutter #플러터 #프로젝트 #파이어베이스 #파이어스토어 #Firebase #FireStore
- 플레이스토어 앱등록
- 앱번들
- GetX #CustomScrollView #Flutter
- Flutter #플러터 #모바일앱만들기 #GetX
- flutter #android #androidstudio
- 초성게임앱 #플러터앱 #플러터카운트다운
Archives
- Today
- Total
이코노딩
[Flutter Project] 플레이어 설정 만들기 본문
✅시작
플레이어를 이름을 설정할 수 있는 기능 만들기,
1️⃣ 기본 이름은 플레이어1~플레이어10까지이다.
2️⃣ 플레이어의 이름이 변경된 후 추가되는 플레이어가 있을 경우 기존 플레이어의 이름은 그대로여야한다.
3️⃣ 플레이어의 이름이 변경된 후 빠지는 플레이어는 뒤에서 부터 빠진다.
☑️Code
Padding(
padding: EdgeInsets.all(10.r),
child:Divider(height: 5.h,thickness: 2,color: const Color(0xffaecdff),)),
Get.put(SettingController()).playerList.isEmpty ?
Expanded(child: Text('먼저 인원수를 지정한 후,\n설정페이지로 들어와주세요.', style: TextStyle(color:Colors.red, fontWeight: FontWeight.bold,fontSize: 20.sp),textAlign: TextAlign.center,)) :
Expanded(
child: Container(
padding: EdgeInsets.symmetric(horizontal: 16.w),
child: ListView.separated(
itemCount: Get.put(SettingController()).playerList.length,
itemBuilder: (BuildContext ctx, int index){
return Container(
color: Colors.white,
height: 30.h,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Row(
children: [
SizedBox(width: 10.w,),
Text('${index+1}', style: TextStyle(fontSize: 15.sp, fontWeight: FontWeight.bold),),
SizedBox(width: 30.w,),
Image.asset(Get.put(SettingController()).playerList[index].image, height: 30.h),
SizedBox(width: 20.w,),
SizedBox(
height: 60.h,
width: 200.w,
child: TextFormField(
controller: Get.put(PlayerSettingController()).txtController[index],
decoration: InputDecoration(
contentPadding: EdgeInsets.symmetric(vertical: 6.h),
hintText: Get.put(SettingController()).playerList[index].name,
hintStyle: TextStyle(color: Colors.grey.withOpacity(0.4)),
suffix: IconButton(
alignment: Alignment.bottomCenter,
icon: Icon(Icons.clear, color: const Color(0xffaecdff),size: 24.sp,),
onPressed: () => Get.put(PlayerSettingController()).txtController[index].clear(),
),
enabledBorder: UnderlineInputBorder(
borderSide: BorderSide(
color: Colors.grey.withOpacity(0.4),
),
),
focusedBorder: const UnderlineInputBorder(
borderSide: BorderSide(
color: Color(0xffaecdff)
)
),
),
cursorColor: const Color(0xffaecdff),
style: TextStyle(
fontSize: 16.sp, color: const Color(0xffaecdff), fontWeight: FontWeight.bold
),
textAlignVertical: TextAlignVertical.bottom,
),
)
],
),
],
),
);
},
separatorBuilder: (BuildContext ctx, int index){
return const Divider();
},
),
),
),
플레이어 수를 지정하지 않고 들어갈 경우 플레이어 설정 후 들어오라는 문구 출력,
플레이어수가 지정되있으면 ListView로 플레이어 리스트가 나타나고 전에 이름은 hint text로 나타남,
☑️Controller Code
class PlayerSettingController extends GetxController{
List<TextEditingController> txtController = [];
@override
void onInit() {
// TODO: implement onInit
super.onInit();
makeTxtController();
}
void makeTxtController(){
for(var i =0; i<Get.put(SettingController()).playerList.length; i++){
txtController.add(TextEditingController());
}
}
void saveTXT(){
for(var i = 0; i< Get.put(SettingController()).playerList.length;i++){
if((Get.put(SettingController()).playerList[i].name = txtController[i].text).isNotEmpty) {
Get.put(SettingController()).playerList[i].name = txtController[i].text;
}else if(txtController[i].text.isEmpty){
Get.put(SettingController()).playerList[i].name = '플레이어${i+1}';
}
}
}
}
컨트롤러가 실행될 때, (플레이어 설정 페이지가 켜질 때) 플레이어 수만큼 TextEditController를 생성해준 후 리스트에 표시
저장을 누르면 SettingController에있는 PlayerList에 name에 넣어주고 TextEdit의 text가 비어있을 경우 기본 이름으로 들어가도록 만들었다.
그리고 저장을 하지 않고 나갈경우 다이얼로그로 저장되지 않았음을 경고해주게 했다.
for(var i = 0; i< Get.put(PlayerSettingController()).txtController.length;i++){
if(Get.put(PlayerSettingController()).txtController[i].text != Get.put(SettingController()).playerList[i].name){
backWarn();
break;
}
if(i == Get.put(PlayerSettingController()).txtController.length-1){
Get.back();
}
}
❌ 구성상 텍스트 필드에서 전에 쓰던 이름은 hint로 표시되고, text는 비어 있는 상태라 기존이름이 저장 되지않음.
✔️개선
for(var i = 0; i< Get.put(PlayerSettingController()).txtController.length; i++){
if(Get.put(PlayerSettingController()).txtController[i].text.isNotEmpty && Get.put(PlayerSettingController()).txtController[i].text != Get.put(SettingController()).playerList[i].name){
backWarn();
break;
}else{
if(i == Get.put(PlayerSettingController()).txtController.length - 1){
Get.back();
}
}
}
✅결과
'프로젝트 > 애미티' 카테고리의 다른 글
[Flutter Project] Flutter TTS Package (0) | 2023.03.26 |
---|---|
[Flutter Project] Splash 와 App Icon 적용하기 (0) | 2023.03.24 |
[Flutter Project] Firebase와 앱 연동하기 <데이터 불러오기> (0) | 2023.03.24 |
[Flutter Project] FireBase와 앱 연동해보기 <앱 등록> (0) | 2023.03.23 |
[Flutter Project] Carouse_Slider Package (0) | 2023.03.23 |