|
|
|
import 'dart:async';
|
|
|
|
|
|
|
|
import 'package:common_utils/common_utils.dart';
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter_screenutil/screenutil.dart';
|
|
|
|
import 'package:one_key/app.dart';
|
|
|
|
import 'package:one_key/provider/other_login_provider.dart';
|
|
|
|
import 'package:one_key/res/colors.dart';
|
|
|
|
import 'package:one_key/utils/navigator_util.dart';
|
|
|
|
import 'package:one_key/utils/utils.dart';
|
|
...
|
...
|
@@ -10,6 +12,7 @@ import 'package:one_key/widgets/h_empty_view.dart'; |
|
|
|
import 'package:one_key/widgets/round_button.dart';
|
|
|
|
import 'package:one_key/widgets/system_app_bar.dart';
|
|
|
|
import 'package:one_key/widgets/v_empty_view.dart';
|
|
|
|
import 'package:provider/provider.dart';
|
|
|
|
|
|
|
|
class BindingPhone extends StatefulWidget {
|
|
|
|
BindingPhone({Key key}) : super(key: key);
|
|
...
|
...
|
@@ -30,6 +33,8 @@ class _BindingPhoneState extends State<BindingPhone> { |
|
|
|
|
|
|
|
String phone;
|
|
|
|
String code;
|
|
|
|
bool enabled = true; //手机号码框是否可以编辑
|
|
|
|
bool codeEnabled = false; //验证码是否可用
|
|
|
|
|
|
|
|
@override
|
|
|
|
void initState() {
|
|
...
|
...
|
@@ -46,14 +51,18 @@ class _BindingPhoneState extends State<BindingPhone> { |
|
|
|
}
|
|
|
|
|
|
|
|
///倒计时方法
|
|
|
|
startCountdown() {
|
|
|
|
Utils.showToast('短信验证码已发送,请注意查收');
|
|
|
|
countdownTime = 60;
|
|
|
|
startCountdown(OtherLoginProvider model) {
|
|
|
|
countdownTime = 300;
|
|
|
|
final call = (timer) {
|
|
|
|
setState(() {
|
|
|
|
if (countdownTime < 1) {
|
|
|
|
// model.code = null;
|
|
|
|
enabled = true;
|
|
|
|
codeEnabled = false;
|
|
|
|
_timer.cancel();
|
|
|
|
} else {
|
|
|
|
enabled = false;
|
|
|
|
codeEnabled = true;
|
|
|
|
countdownTime -= 1;
|
|
|
|
}
|
|
|
|
});
|
|
...
|
...
|
@@ -85,179 +94,220 @@ class _BindingPhoneState extends State<BindingPhone> { |
|
|
|
Expanded(
|
|
|
|
child: SingleChildScrollView(
|
|
|
|
controller: _controller,
|
|
|
|
child: Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: [
|
|
|
|
Text('绑定您的手机号',
|
|
|
|
style: TextStyle(
|
|
|
|
fontWeight: FontWeight.bold,
|
|
|
|
color: MyColours.color_333333,
|
|
|
|
fontSize: ScreenUtil().setSp(40))),
|
|
|
|
VEmptyView(100),
|
|
|
|
Container(
|
|
|
|
height: ScreenUtil().setHeight(52 * 2),
|
|
|
|
// width: ScreenUtil().setWidth(611),
|
|
|
|
padding: EdgeInsets.only(
|
|
|
|
left: ScreenUtil().setWidth(20)),
|
|
|
|
margin: EdgeInsets.only(
|
|
|
|
top: ScreenUtil().setHeight(8)),
|
|
|
|
alignment: Alignment.center,
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
border: Border.all(
|
|
|
|
color: MyColours.color_bff6f7,
|
|
|
|
width: ScreenUtil().setWidth(2)),
|
|
|
|
borderRadius: BorderRadius.circular(
|
|
|
|
ScreenUtil().setWidth(10))),
|
|
|
|
child: Row(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.center,
|
|
|
|
children: <Widget>[
|
|
|
|
HEmptyView(30),
|
|
|
|
Text(
|
|
|
|
"手机号",
|
|
|
|
style: TextStyle(
|
|
|
|
color: MyColours.color_333333,
|
|
|
|
fontSize: ScreenUtil().setSp(26)),
|
|
|
|
),
|
|
|
|
HEmptyView(30),
|
|
|
|
Expanded(
|
|
|
|
child: TextField(
|
|
|
|
focusNode: _phoneNode,
|
|
|
|
child: Consumer<OtherLoginProvider>(
|
|
|
|
builder: (context, model, _) {
|
|
|
|
return Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: [
|
|
|
|
Text('绑定您的手机号',
|
|
|
|
style: TextStyle(
|
|
|
|
fontWeight: FontWeight.bold,
|
|
|
|
color: MyColours.color_333333,
|
|
|
|
fontSize: ScreenUtil().setSp(40))),
|
|
|
|
VEmptyView(100),
|
|
|
|
Container(
|
|
|
|
height: ScreenUtil().setHeight(52 * 2),
|
|
|
|
// width: ScreenUtil().setWidth(611),
|
|
|
|
padding: EdgeInsets.only(
|
|
|
|
left: ScreenUtil().setWidth(20)),
|
|
|
|
margin: EdgeInsets.only(
|
|
|
|
top: ScreenUtil().setHeight(8)),
|
|
|
|
alignment: Alignment.center,
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
border: Border.all(
|
|
|
|
color: MyColours.color_bff6f7,
|
|
|
|
width: ScreenUtil().setWidth(2)),
|
|
|
|
borderRadius: BorderRadius.circular(
|
|
|
|
ScreenUtil().setWidth(10))),
|
|
|
|
child: Row(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.center,
|
|
|
|
children: <Widget>[
|
|
|
|
HEmptyView(30),
|
|
|
|
Text(
|
|
|
|
"手机号",
|
|
|
|
style: TextStyle(
|
|
|
|
color: MyColours.color_353535,
|
|
|
|
fontSize: ScreenUtil().setSp(28)),
|
|
|
|
decoration: InputDecoration(
|
|
|
|
hintText: "请输入手机号",
|
|
|
|
hintStyle: TextStyle(
|
|
|
|
color: MyColours.color_999999,
|
|
|
|
fontSize: ScreenUtil().setSp(26)),
|
|
|
|
border: InputBorder.none,
|
|
|
|
contentPadding: EdgeInsets.fromLTRB(
|
|
|
|
0,
|
|
|
|
ScreenUtil().setWidth(28),
|
|
|
|
ScreenUtil().setWidth(30),
|
|
|
|
ScreenUtil().setWidth(28)),
|
|
|
|
),
|
|
|
|
onChanged: (value) {
|
|
|
|
phone = value;
|
|
|
|
},
|
|
|
|
onEditingComplete: () {
|
|
|
|
FocusScope.of(context).requestFocus(
|
|
|
|
FocusNode()); //点击空白处隐藏键盘
|
|
|
|
},
|
|
|
|
keyboardType: TextInputType.number,
|
|
|
|
color: MyColours.color_333333,
|
|
|
|
fontSize: ScreenUtil().setSp(26)),
|
|
|
|
),
|
|
|
|
)
|
|
|
|
],
|
|
|
|
)),
|
|
|
|
VEmptyView(10),
|
|
|
|
Container(
|
|
|
|
height: ScreenUtil().setHeight(52 * 2),
|
|
|
|
// width: ScreenUtil().setWidth(611),
|
|
|
|
padding: EdgeInsets.only(
|
|
|
|
left: ScreenUtil().setWidth(20)),
|
|
|
|
margin: EdgeInsets.only(
|
|
|
|
top: ScreenUtil().setHeight(8)),
|
|
|
|
alignment: Alignment.center,
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
border: Border.all(
|
|
|
|
color: MyColours.color_bff6f7,
|
|
|
|
width: ScreenUtil().setWidth(2)),
|
|
|
|
borderRadius: BorderRadius.circular(
|
|
|
|
ScreenUtil().setWidth(10))),
|
|
|
|
child: Row(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.center,
|
|
|
|
children: <Widget>[
|
|
|
|
HEmptyView(30),
|
|
|
|
Text(
|
|
|
|
"验证码",
|
|
|
|
style: TextStyle(
|
|
|
|
color: MyColours.color_333333,
|
|
|
|
fontSize: ScreenUtil().setSp(26)),
|
|
|
|
),
|
|
|
|
HEmptyView(30),
|
|
|
|
Expanded(
|
|
|
|
child: TextField(
|
|
|
|
focusNode: _codeNode,
|
|
|
|
HEmptyView(30),
|
|
|
|
Expanded(
|
|
|
|
child: TextField(
|
|
|
|
enabled: enabled,
|
|
|
|
focusNode: _phoneNode,
|
|
|
|
style: TextStyle(
|
|
|
|
color: MyColours.color_353535,
|
|
|
|
fontSize: ScreenUtil().setSp(28)),
|
|
|
|
decoration: InputDecoration(
|
|
|
|
hintText: "请输入手机号",
|
|
|
|
hintStyle: TextStyle(
|
|
|
|
color: MyColours.color_999999,
|
|
|
|
fontSize: ScreenUtil().setSp(26)),
|
|
|
|
border: InputBorder.none,
|
|
|
|
contentPadding: EdgeInsets.fromLTRB(
|
|
|
|
0,
|
|
|
|
ScreenUtil().setWidth(28),
|
|
|
|
ScreenUtil().setWidth(30),
|
|
|
|
ScreenUtil().setWidth(28)),
|
|
|
|
),
|
|
|
|
onChanged: (value) {
|
|
|
|
phone = value;
|
|
|
|
},
|
|
|
|
onEditingComplete: () {
|
|
|
|
FocusScope.of(context).requestFocus(
|
|
|
|
FocusNode()); //点击空白处隐藏键盘
|
|
|
|
},
|
|
|
|
keyboardType: TextInputType.number,
|
|
|
|
),
|
|
|
|
)
|
|
|
|
],
|
|
|
|
)),
|
|
|
|
VEmptyView(10),
|
|
|
|
Container(
|
|
|
|
height: ScreenUtil().setHeight(52 * 2),
|
|
|
|
// width: ScreenUtil().setWidth(611),
|
|
|
|
padding: EdgeInsets.only(
|
|
|
|
left: ScreenUtil().setWidth(20)),
|
|
|
|
margin: EdgeInsets.only(
|
|
|
|
top: ScreenUtil().setHeight(8)),
|
|
|
|
alignment: Alignment.center,
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
border: Border.all(
|
|
|
|
color: MyColours.color_bff6f7,
|
|
|
|
width: ScreenUtil().setWidth(2)),
|
|
|
|
borderRadius: BorderRadius.circular(
|
|
|
|
ScreenUtil().setWidth(10))),
|
|
|
|
child: Row(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.center,
|
|
|
|
children: <Widget>[
|
|
|
|
HEmptyView(30),
|
|
|
|
Text(
|
|
|
|
"验证码",
|
|
|
|
style: TextStyle(
|
|
|
|
color: MyColours.color_353535,
|
|
|
|
fontSize: ScreenUtil().setSp(28)),
|
|
|
|
decoration: InputDecoration(
|
|
|
|
hintText: "请输入验证码",
|
|
|
|
hintStyle: TextStyle(
|
|
|
|
color: MyColours.color_999999,
|
|
|
|
fontSize: ScreenUtil().setSp(26)),
|
|
|
|
border: InputBorder.none,
|
|
|
|
contentPadding: EdgeInsets.fromLTRB(
|
|
|
|
0,
|
|
|
|
ScreenUtil().setWidth(28),
|
|
|
|
ScreenUtil().setWidth(30),
|
|
|
|
ScreenUtil().setWidth(28)),
|
|
|
|
color: MyColours.color_333333,
|
|
|
|
fontSize: ScreenUtil().setSp(26)),
|
|
|
|
),
|
|
|
|
HEmptyView(30),
|
|
|
|
Expanded(
|
|
|
|
child: TextField(
|
|
|
|
focusNode: _codeNode,
|
|
|
|
style: TextStyle(
|
|
|
|
color: MyColours.color_353535,
|
|
|
|
fontSize: ScreenUtil().setSp(28)),
|
|
|
|
decoration: InputDecoration(
|
|
|
|
hintText: "请输入验证码",
|
|
|
|
hintStyle: TextStyle(
|
|
|
|
color: MyColours.color_999999,
|
|
|
|
fontSize: ScreenUtil().setSp(26)),
|
|
|
|
border: InputBorder.none,
|
|
|
|
contentPadding: EdgeInsets.fromLTRB(
|
|
|
|
0,
|
|
|
|
ScreenUtil().setWidth(28),
|
|
|
|
ScreenUtil().setWidth(30),
|
|
|
|
ScreenUtil().setWidth(28)),
|
|
|
|
),
|
|
|
|
onChanged: (value) {
|
|
|
|
code = value;
|
|
|
|
},
|
|
|
|
onEditingComplete: () {
|
|
|
|
FocusScope.of(context).requestFocus(
|
|
|
|
FocusNode()); //点击空白处隐藏键盘
|
|
|
|
},
|
|
|
|
keyboardType: TextInputType.number,
|
|
|
|
),
|
|
|
|
onChanged: (value) {
|
|
|
|
code = value;
|
|
|
|
},
|
|
|
|
onEditingComplete: () {
|
|
|
|
FocusScope.of(context).requestFocus(
|
|
|
|
FocusNode()); //点击空白处隐藏键盘
|
|
|
|
),
|
|
|
|
HEmptyView(10),
|
|
|
|
RoundButton(
|
|
|
|
height: ScreenUtil().setWidth(84),
|
|
|
|
text: countdownTime > 0
|
|
|
|
? "${Utils.durationTransform(countdownTime)}后重新获取"
|
|
|
|
: "获取验证码",
|
|
|
|
radius: ScreenUtil().setWidth(10),
|
|
|
|
textColor: MyColours.color_199095,
|
|
|
|
gradientStart: MyColours.color_ffffff,
|
|
|
|
gradientEnd: MyColours.color_ffffff,
|
|
|
|
borderColor: Colors.transparent,
|
|
|
|
fontSize: 26,
|
|
|
|
isBold: false,
|
|
|
|
onPressed: () async {
|
|
|
|
if (countdownTime == 0) {
|
|
|
|
if (phone == null ||
|
|
|
|
phone.trim().length == 0) {
|
|
|
|
Utils.showToast('请输入手机号码');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!Utils.phoneRegExp(phone)) {
|
|
|
|
Utils.showToast(
|
|
|
|
'您输入的手机号码格式不正确,请重新输入');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
model.code = Utils.randomBit(4);
|
|
|
|
Map<String, String> params = {
|
|
|
|
"phone": phone,
|
|
|
|
"code": model.code,
|
|
|
|
};
|
|
|
|
startCountdown(model);
|
|
|
|
bool success = await model
|
|
|
|
.getPhoneCode(context, params);
|
|
|
|
if (!success) {
|
|
|
|
_timer.cancel();
|
|
|
|
} else {
|
|
|
|
Utils.showToast('短信验证码已发送,请注意查收');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
keyboardType: TextInputType.number,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
HEmptyView(10),
|
|
|
|
RoundButton(
|
|
|
|
height: ScreenUtil().setWidth(84),
|
|
|
|
text: countdownTime > 0
|
|
|
|
? "${countdownTime}s后重新获取"
|
|
|
|
: "获取验证码",
|
|
|
|
radius: ScreenUtil().setWidth(10),
|
|
|
|
textColor: MyColours.color_199095,
|
|
|
|
gradientStart: MyColours.color_ffffff,
|
|
|
|
gradientEnd: MyColours.color_ffffff,
|
|
|
|
borderColor: Colors.transparent,
|
|
|
|
fontSize: 26,
|
|
|
|
isBold: false,
|
|
|
|
onPressed: () {
|
|
|
|
if (countdownTime == 0) {
|
|
|
|
startCountdown();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
),
|
|
|
|
HEmptyView(20),
|
|
|
|
],
|
|
|
|
)),
|
|
|
|
VEmptyView(120),
|
|
|
|
RoundButton(
|
|
|
|
text: '提交',
|
|
|
|
gradientStart: MyColours.color_199095,
|
|
|
|
gradientEnd: MyColours.color_199095,
|
|
|
|
// borderColor: MyColours.color_999999,
|
|
|
|
radius: ScreenUtil().setWidth(20),
|
|
|
|
fontSize: 34,
|
|
|
|
isBold: false,
|
|
|
|
onPressed: () {
|
|
|
|
if (phone == null || phone.trim().length == 0) {
|
|
|
|
Utils.showToast('请输入手机号码');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (code == null || code.trim().length == 0) {
|
|
|
|
Utils.showToast('请输入验证码');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
//接口确认验证码是否正确
|
|
|
|
HEmptyView(20),
|
|
|
|
],
|
|
|
|
)),
|
|
|
|
VEmptyView(120),
|
|
|
|
RoundButton(
|
|
|
|
text: '确定',
|
|
|
|
gradientStart: MyColours.color_199095,
|
|
|
|
gradientEnd: MyColours.color_199095,
|
|
|
|
// borderColor: MyColours.color_999999,
|
|
|
|
radius: ScreenUtil().setWidth(20),
|
|
|
|
fontSize: 34,
|
|
|
|
isBold: false,
|
|
|
|
onPressed: () {
|
|
|
|
NavigatorUtil.goIfNeedCreateStorePage(context);
|
|
|
|
if (phone == null || phone.trim().length == 0) {
|
|
|
|
Utils.showToast('请输入手机号码');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (code == null || code.trim().length == 0) {
|
|
|
|
Utils.showToast('请输入验证码');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (model.code != null && !codeEnabled) {
|
|
|
|
Utils.showToast('验证码已失效,请重新获取');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (model.code == null) {
|
|
|
|
Utils.showToast('请获取验证码');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (model.code != code) {
|
|
|
|
Utils.showToast('您输入的验证码不正确,请重新输入');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// if (countdownTime < 1) {
|
|
|
|
// Utils.showToast('验证码已失效,请重新获取');
|
|
|
|
// return;
|
|
|
|
// }
|
|
|
|
|
|
|
|
// 正确
|
|
|
|
//真正登录成功标志
|
|
|
|
App.sp.setBool("isLogin", true);
|
|
|
|
NavigatorUtil.goIfNeedCreateStorePage(context);
|
|
|
|
//错误
|
|
|
|
// Utils.showToast('您输入的验证码有误,请重新输入');
|
|
|
|
},
|
|
|
|
)
|
|
|
|
// 正确
|
|
|
|
//真正登录成功标志
|
|
|
|
App.sp.setBool("isLogin", true);
|
|
|
|
NavigatorUtil.goIfNeedCreateStorePage(context);
|
|
|
|
//错误
|
|
|
|
// Utils.showToast('您输入的验证码有误,请重新输入');
|
|
|
|
},
|
|
|
|
)
|
|
|
|
|
|
|
|
// Spacer(),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
// Spacer(),
|
|
|
|
],
|
|
|
|
);
|
|
|
|
}),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
...
|
...
|
|