onTapSendButton method Null safety

void onTapSendButton(
  1. BuildContext context
)

Implementation

void onTapSendButton(BuildContext context) async {
  LogManager().addLog("휴대폰 인증 코드 발송 버튼 누름", screen: runtimeType.toString());
  String username = usernameController.text.trim();
  // String phone = phoneNumberController.text.trim();

  // EventService().eventBus.fire(PopupEvent(type: PopupType.loading, action: PopupAction.show));

  String errTitle = "";
  String errContent = "";

  if (username.isEmpty) {
    errTitle = "아이디 누락";
    errContent = "아이디를 입력하세요.";
  }
  // if (phone.isEmpty) {
  //   errTitle = "올바른 핸드폰 번호";
  //   errContent = "올바른 핸드폰 번호를 입력하세요. 계정 인증에 꼭 필요합니다.";
  // }
  // if (Validators.phoneNumberValidator(phone)) {
  //   phone = "+82" + phone.substring(1);
  //   phone = phone.replaceAll("-", "");
  // } else {
  //   errTitle = "올바른 핸드폰 번호";
  //   errContent = "올바른 핸드폰 번호를 입력하세요.";
  // }

  if (errTitle != "" || errContent != "") {
    EventService().eventBus.fire(
      PopupEvent(
        type: PopupType.alert,
        action: PopupAction.show,
        data: {"title": errTitle, "content": errContent},
        onClose: () {
          Navigator.of(context, rootNavigator: true).popUntil((route) => !route.settings.name!.startsWith(PopupScreen.routeName));
        },
      ),
    );
    return;
  }

  try {
    LogManager().addLog("휴대폰 인증 코드 발송 시도", screen: runtimeType.toString());
    await Amplify.Auth.resendSignUpCode(username: username);
    LogManager().addLog("휴대폰 인증 코드 발송 성공", screen: runtimeType.toString());
    Navigator.of(context, rootNavigator: true).popUntil((route) => !route.settings.name!.startsWith(PopupScreen.routeName));
    Navigator.of(context, rootNavigator: true).pushNamed(PhoneAuthScreen.routeName, arguments: PhoneAuthScreenArguments(username: username));
  } on AuthException catch (e) {
    LogManager().addLog(e.toString(), screen: runtimeType.toString());
    EventService().eventBus.fire(
          PopupEvent(
            type: PopupType.alert,
            action: PopupAction.show,
            data: {"title": "오류", "content": e.message},
            onClose: () {
              Navigator.of(context, rootNavigator: true).popUntil((route) => !route.settings.name!.startsWith(PopupScreen.routeName));
            },
          ),
        );
  }
}