class LoginDialog extends Dialog {
/// 弹窗宽度
final double width;
/// 弹窗长度
final double height;
/// 是否有圆角
final bool round;
final TextEditingController? controller;
/// 确认回调函数
final void Function()? fn1;
final VoidCallback press;
/// 确认按钮文字
/// 取消回调函数
final Function(String)? onChanged;
/// 取消按钮文字
LoginDialog(
this.press, {
Key? key,
required this.width,
required this.height,
this.controller,
this.round = true,
this.onChanged,
this.fn1,
}) : super(key: key);
@override
Widget build(BuildContext context) {
return Material(
type: MaterialType.transparency,
child: Center(
child: Container(
width: width,
decoration: BoxDecoration(
color: Colors.white,
borderRadius:
round != true ? BorderRadius.zero : BorderRadius.circular(32.w),
),
height: height,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Row(
children: [
SizedBox(
width: 30.w,
),
GetBuilder<InputPhoneController>(builder: (_) {
return Container(
alignment: Alignment.center,
height: 112.w,
width: 260.w,
child: Image.file(
File(_.path),
fit: BoxFit.fitWidth,
),
);
}).onTap(() {
fn1?.call();
}),
SizedBox(
width: 20.w,
),
Container(
alignment: Alignment.center,
height: 56 * 2.w,
width: 180 * 2.w,
decoration: BoxDecoration(
color: Colours.greyF5,
borderRadius: BorderRadius.circular(136.w),
),
child: TextField(
onChanged: onChanged,
controller: controller,
maxLength: 4,
decoration: InputDecoration(
border: InputBorder.none,
counterText: "",
hintText: "请输入校验结果",
contentPadding: EdgeInsets.only(left: 50.w),
hintStyle: TextStyle(
fontSize: 28.f,
color: Colours.greyB5,
fontWeight: FontWeight.w500),
)),
).paddingOnly(right: 20.w)
],
),
SizedBox(
height: 44.w,
),
Container(
height: 112.w,
width: 624.w,
child: TongpinPrimaryButton(
color: Colours.app_main_blue,
text: "获取验证码",
press: press,
),
)
],
),
)));
}
}
void getCode() {
DioUtil.getInstance()!.requestNetwork(Apis.URL_VERIFICATIONCODE, "get",
params: {}, onSuccess: (dynamic data) async {
String path = await FileUtil.createFileFromString(data['code']);
print(path);
this.path = path;
this.key = data['key'];
update();
}, onError: (errno, msg) {});
}
void comparison() {
DioUtil.getInstance()!.requestNetwork(Apis.URL_COMPARISION, "get",
params: {'inCode': value, 'key': key}, onSuccess: (dynamic data) async {
Get.back();
sendCode();
}, onError: (errno, msg) {
getCode();
inputController.clear();
update();
});
}
TongpinPrimaryButton(
color: controller.complete == true
? Colours.app_main_blue
: Colours.app_main_blue_light,
text: "获取验证码",
press: () async {
RegExp exp = RegExp(
r'^((13[0-9])|(14[0-9])|(15[0-9])|(16[0-9])|(17[0-9])|(18[0-9])|(19[0-9]))\d{8}$');
bool matched = exp.hasMatch(controller.phoneController.text);
if(matched){
Navigator.push(
context,
MaterialPageRoute(builder: (context) {
return BlockPuzzleCaptchaPage(onSuccess: (s){
_.sendCode();
},);
}),
);
_.getCode();
await showDialog(
barrierColor: Color(0xb2000000),
context: context,
builder: (BuildContext context) {
return LoginDialog(
() {
_.comparison();
// _.sendCode();
},
controller: _.inputController,
height: 388.w,
width: 704.w,
fn1: () {
_.getCode();
_.update();
},
onChanged: (v) {
_.value = v;
_.update();
},
);
},
);
}else{
ToastUtil.error("请输入正确的手机号");
}
},
);