app-starlock/star_lock/lib/login/register/starLock_register_logic.dart
2023-10-07 18:55:59 +08:00

91 lines
2.4 KiB
Dart

import 'dart:async';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import '../../network/api_repository.dart';
import '../../tools/baseGetXController.dart';
import '../../tools/toast.dart';
import 'starLock_register_state.dart';
class StarLockRegisterLogic extends BaseGetXController {
final StarLockRegisterState state = StarLockRegisterState();
late Timer _timer;
void _startTimer() {
_timer = Timer.periodic(1.seconds, (timer) {
if (state.currentSecond > 1) {
state.currentSecond--;
} else {
_cancelTimer();
state.currentSecond = state.totalSeconds;
}
state.resetResend();
});
}
void _cancelTimer() {
_timer.cancel();
// _timer = null;
}
void register() async {
var entity = await ApiRepository.to.register(
state.countryCode.value,
state.countryId.value,
state.phoneOrEmailStr.value,
state.pwd.value,
"477E6814-289D-402A-9F49-F89A8BD05D63",
state.verificationCode.value);
if (entity.errorCode!.codeIsSuccessful) {
// await loginSuccess(loginEntity: entity);
Toast.show(msg: "注册成功");
Get.back();
} else {}
}
void sendValidationCode() async {
var entity = await ApiRepository.to.sendValidationCode(
// state.countryCode.value,
"+86",
state.phoneOrEmailStr.value,
state.isIphoneType.value ? "1" : "2",
'1',
"B748F838-94EE-4BDB-A0E6-7B2D16849792",
state.xWidth.value.toString());
if (entity.errorCode!.codeIsSuccessful) {
_startTimer();
} else {
}
}
void checkNext(TextEditingController controller) {
changeInput(controller);
}
void changeInput(TextEditingController controller) {
if (controller == state.phoneOrEmailController) {
state.phoneOrEmailStr.value = controller.text;
state.phoneOrEmailStrIsOK.value = state.phoneOrEmailStr.value.isNotEmpty;
}
if (controller == state.pwdController) {
state.pwd.value = controller.text;
}
if (controller == state.sureController) {
state.surePwd.value = controller.text;
}
if (controller == state.codeController) {
state.verificationCode.value = controller.text;
}
_resetCanSub();
}
void _resetCanSub() {
state.canSub.value = state.pwdIsOK &&
state.codeIsOK &&
(state.isIphoneType.value ? state.isIphone : state.isEmail);
print("22222:${state.canSub.value}");
}
}