Skip to content

Commit

Permalink
M3-168 Feat : 로그인 화면에 정규식 적용
Browse files Browse the repository at this point in the history
  • Loading branch information
tkdals802 committed Jul 19, 2024
1 parent 05c899e commit c6ea7ee
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 24 deletions.
51 changes: 42 additions & 9 deletions lib/controllers/sign_up_controller.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'package:dio/dio.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:image_picker/image_picker.dart';

Expand All @@ -11,13 +13,16 @@ class SignUpController extends GetxController {

var profileImage = Rxn<XFile>();

final RegExp regExp = RegExp(r'^[A-Za-z가-힣0-9]{3,10}$');

late RxList<bool> toggleSelection;
bool isMale = true;
bool isFemale = false;

RxString nickname = ''.obs;
RxInt birthYear = 2000.obs;
RxString gender = 'MALE'.obs;
RxString nicknameValidation = "".obs;
RxBool isNicknameTyped = false.obs;

@override
Expand Down Expand Up @@ -59,16 +64,44 @@ class SignUpController extends GetxController {
}
}

void completeRegistration() async {
int? statusCode = await userService.putUserInfo(
gender: gender.value,
birthYear: birthYear.value,
nickname: nickname.value,
profileImagePath: profileImage.value?.path,
void showErrorDialog(String message) {
Get.dialog(
AlertDialog(
title: Text(message),
actions: [
TextButton(
child: Text('확인'),
onPressed: () {
Get.back();
},
),
],
),
);
if (statusCode == 200) {
await secureStorage.writeSignupStatus("true");
Get.offAllNamed('/main');
}

void completeRegistration() async {
try {
int? statusCode = await userService.putUserInfo(
gender: gender.value,
birthYear: birthYear.value,
nickname: nickname.value,
profileImagePath: profileImage.value?.path,
);
if (statusCode == 200) {
await secureStorage.writeSignupStatus("true");
Get.offAllNamed('/main');
}
} catch (e) {
if (!regExp.hasMatch(nickname.value)) {
showErrorDialog('닉네임 형식이 맞지 않습니다!');
}
if (e is DioException) {
final response = e.response;
if (response != null && response.statusCode == 400) {
showErrorDialog('중복된 닉네임입니다!');
}
}
}
}
}
3 changes: 1 addition & 2 deletions lib/controllers/user_info_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ class UserInfoController extends GetxController {
void showErrorDialog(String message) {
Get.dialog(
AlertDialog(
title: Text('$message'),
title: Text(message),
actions: [
TextButton(
child: Text('확인'),
Expand All @@ -108,7 +108,6 @@ class UserInfoController extends GetxController {
nickname: nickname.value,
profileImagePath: profileImage.value?.path,
);

if (statusCode == 200) {
Get.offAllNamed('/main');
}
Expand Down
30 changes: 23 additions & 7 deletions lib/screens/sign_up_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@ class SignUpScreen extends StatelessWidget {
@override
Widget build(BuildContext context) {
final SignUpController controller = Get.put(SignUpController());
final RegExp regExp = RegExp(r'^[A-Za-z가-힣0-9]{3,10}$');
const int lowBoundYear = 1900;
const int upperBoundYear = 2024;

return GestureDetector(
onTap: (){
onTap: () {
FocusScope.of(context).unfocus();
},
child: Scaffold(
Expand Down Expand Up @@ -86,13 +87,28 @@ class SignUpScreen extends StatelessWidget {
Container(
color: Color(0xffD9D9D9),
child: TextField(
decoration: InputDecoration(
decoration: InputDecoration(
border: InputBorder.none,
contentPadding:
EdgeInsets.symmetric(horizontal: 8.0, vertical: 12.0),
contentPadding: EdgeInsets.symmetric(
horizontal: 8.0,
vertical: 12.0,
),
),
style: TextStyle(fontSize: 16.0),
onChanged: controller.updateNickname,
onChanged: (value) {
controller.updateNickname(value);
if (!regExp.hasMatch(value)) {
controller.nicknameValidation.value = "형식에 맞지 않습니다!";
} else {
controller.nicknameValidation.value = "";
}
},
),
),
Align(
alignment: Alignment.centerLeft,
child: Obx(
() => Text(controller.nicknameValidation.value),
),
),
],
Expand Down Expand Up @@ -160,8 +176,8 @@ class SignUpScreen extends StatelessWidget {
Obx(
() => ToggleButtons(
constraints: BoxConstraints.expand(
width:
(MediaQuery.of(context).size.width - 100) / 2,), //
width: (MediaQuery.of(context).size.width - 100) / 2,
), //
isSelected: controller.toggleSelection,
onPressed: controller.updateSelectedGender,
children: [
Expand Down
11 changes: 5 additions & 6 deletions lib/screens/user_info_update_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import 'dart:io';

import 'package:dropdown_button2/dropdown_button2.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:get/get.dart';

import '../controllers/user_info_controller.dart';
Expand Down Expand Up @@ -108,9 +107,9 @@ class UserInfoUpdateScreen extends StatelessWidget {
onChanged: (value) {
controller.nickname.value = value;
if (!regExp.hasMatch(value)) {
controller.nicknameValidation.value = "형식에 맞지 않습니다!";
print("missmiss match! ${value}");
}else{
controller.nicknameValidation.value =
"형식에 맞지 않습니다!";
} else {
controller.nicknameValidation.value = "";
}
},
Expand All @@ -119,9 +118,9 @@ class UserInfoUpdateScreen extends StatelessWidget {
Align(
alignment: Alignment.centerLeft,
child: Obx(
() => Text('${controller.nicknameValidation.value}'),
() => Text(controller.nicknameValidation.value),
),
)
),
],
),
SizedBox(height: 16),
Expand Down

0 comments on commit c6ea7ee

Please sign in to comment.