|
|
import 'package:bot_toast/bot_toast.dart';
|
|
|
import 'package:flutter/material.dart';
|
|
|
import 'package:flutter/services.dart';
|
|
|
import 'package:project_telephony/utils/headers.dart';
|
|
|
|
|
|
import '../../constants/api.dart';
|
|
|
import '../../model/network/api_client.dart';
|
|
|
import '../../model/network/base_model.dart';
|
|
|
import '../widget/scaffold_theme_widget.dart';
|
|
|
|
|
|
class SetPasswordPage extends StatefulWidget {
|
|
|
const SetPasswordPage({Key? key}) : super(key: key);
|
|
|
|
|
|
@override
|
|
|
_SetPasswordPageState createState() => _SetPasswordPageState();
|
|
|
}
|
|
|
|
|
|
class _SetPasswordPageState extends State<SetPasswordPage> {
|
|
|
late TextEditingController _psdController;
|
|
|
late TextEditingController _psdTwiceController;
|
|
|
final _isOk=false;
|
|
|
|
|
|
static bool isLoginPassword(String input) {
|
|
|
RegExp mobile = RegExp(r"(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{6,16}$");
|
|
|
return mobile.hasMatch(input);
|
|
|
}
|
|
|
|
|
|
@override
|
|
|
void initState() {
|
|
|
super.initState();
|
|
|
_psdController = TextEditingController();
|
|
|
_psdTwiceController = TextEditingController();
|
|
|
}
|
|
|
|
|
|
@override
|
|
|
void dispose() {
|
|
|
_psdController.dispose();
|
|
|
_psdTwiceController.dispose();
|
|
|
super.dispose();
|
|
|
}
|
|
|
|
|
|
@override
|
|
|
Widget build(BuildContext context) {
|
|
|
return ScaffoldThemeWidget(
|
|
|
title: "设置密码",
|
|
|
bottom: "确认",
|
|
|
onTap: () async {
|
|
|
if(_psdController.text==_psdTwiceController.text){
|
|
|
BaseModel res = await apiClient.request(API.app.psdAdd,
|
|
|
data: {"password": _psdController.text});
|
|
|
if(res.code==0){
|
|
|
BotToast.showText(text: "设置成功");
|
|
|
}else{
|
|
|
BotToast.showText(text:"设置密码出错");
|
|
|
}
|
|
|
Get.back();
|
|
|
}else{
|
|
|
BotToast.showText(text: "两次输入的密码不相同");
|
|
|
}
|
|
|
},
|
|
|
isOpacity:_psdController.text.isNotEmpty&&isLoginPassword(_psdController.text),
|
|
|
child: Container(
|
|
|
padding: EdgeInsets.all(40.w),
|
|
|
child: Column(
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
children: [
|
|
|
Row(
|
|
|
children: [
|
|
|
Text(
|
|
|
'新 密 码 ',
|
|
|
style: TextStyle(
|
|
|
fontSize: 30.sp,
|
|
|
),
|
|
|
),
|
|
|
Expanded(
|
|
|
child: Padding(
|
|
|
padding: EdgeInsets.only(left: 10.w),
|
|
|
child: TextField(
|
|
|
onChanged: (value){
|
|
|
_psdController.text=value;
|
|
|
_psdController.value = TextEditingValue(
|
|
|
text: _psdController.text,
|
|
|
selection:
|
|
|
TextSelection.fromPosition(TextPosition(
|
|
|
affinity: TextAffinity.downstream,
|
|
|
offset:
|
|
|
_psdController.text.length,
|
|
|
)));
|
|
|
setState((){});
|
|
|
},
|
|
|
inputFormatters: [FilteringTextInputFormatter.allow(RegExp(r'[A-Za-z0-9_]'))],
|
|
|
controller: _psdController,
|
|
|
decoration: const InputDecoration(
|
|
|
hintText: '填写新密码',
|
|
|
hintStyle: TextStyle(
|
|
|
color: Colors.black38,
|
|
|
),
|
|
|
),
|
|
|
),
|
|
|
)
|
|
|
,
|
|
|
),
|
|
|
],
|
|
|
),
|
|
|
20.hb,
|
|
|
Row(
|
|
|
children: [
|
|
|
Text(
|
|
|
'确认密码 ',
|
|
|
style: TextStyle(
|
|
|
fontSize: 30.sp,
|
|
|
),
|
|
|
),
|
|
|
Expanded(
|
|
|
child: Padding(
|
|
|
padding: EdgeInsets.only(left: 10.w),
|
|
|
child: TextField(
|
|
|
onChanged: (value){
|
|
|
_psdTwiceController.text=value;
|
|
|
_psdTwiceController.value = TextEditingValue(
|
|
|
text: _psdTwiceController.text,
|
|
|
selection:
|
|
|
TextSelection.fromPosition(TextPosition(
|
|
|
affinity: TextAffinity.downstream,
|
|
|
offset:
|
|
|
_psdTwiceController.text.length,
|
|
|
)));
|
|
|
setState((){});
|
|
|
},
|
|
|
inputFormatters: [FilteringTextInputFormatter.allow(RegExp(r'[A-Za-z0-9_]'))],
|
|
|
controller: _psdTwiceController,
|
|
|
decoration: const InputDecoration(
|
|
|
hintText: '再次确认密码',
|
|
|
hintStyle: TextStyle(
|
|
|
color: Colors.black38,
|
|
|
),
|
|
|
),
|
|
|
),
|
|
|
)
|
|
|
,
|
|
|
),
|
|
|
],
|
|
|
),
|
|
|
20.hb,
|
|
|
Text(
|
|
|
'密码必须是6~16位字母、数字、字符的组合',
|
|
|
style: TextStyle(
|
|
|
fontSize: 26.sp,
|
|
|
color: Colors.black38,
|
|
|
),
|
|
|
),
|
|
|
],
|
|
|
),
|
|
|
),
|
|
|
);
|
|
|
}
|
|
|
}
|