123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122 |
- import 'package:flutter/cupertino.dart';
- import 'package:flutter/material.dart';
- import 'package:flutterappfuyou/code/YSlogin.dart';
- import 'package:flutterappfuyou/code/base/YSBase.dart';
- import 'package:flutterappfuyou/code/base/YSNetWorking.dart';
- import 'package:shared_preferences/shared_preferences.dart';
- class YSChangePassWord extends StatefulWidget {
- const YSChangePassWord({Key key}) : super(key: key);
- @override
- _YSChangePassWordState createState() => _YSChangePassWordState();
- }
- class _YSChangePassWordState extends State<YSChangePassWord> {
- List _showArray = [
- {'title':'旧密码','isObscure':true},
- {'title':'新密码','isObscure':true},
- {'title':'再次输入新密码','isObscure':true},
- ];
- TextEditingController _newField = TextEditingController();
- TextEditingController _passField = TextEditingController();
- TextEditingController _wordField = TextEditingController();
- @override
- void dispose() {
- _newField.dispose();
- _passField.dispose();
- _wordField.dispose();
- super.dispose();
- }
- @override
- Widget build(BuildContext context) {
- return YSBase(
- ysright: GestureDetector(
- onTap: () async{
- FocusScope.of(context).unfocus();
- if(_passField.text.isEmpty){
- ysFlutterToast(context, '请输入旧密码');
- return;
- }
- if(_newField.text.isEmpty){
- ysFlutterToast(context, '请输入新密码');
- return;
- }
- if(_wordField.text.isEmpty){
- ysFlutterToast(context, '请再次输入旧密码');
- return;
- }
- if(_newField.text!=_wordField.text){
- ysFlutterToast(context, '两次新密码输入不一致');
- return;
- }
- Map request = {};
- request['password_old'] = _passField.text;
- request['password_confirm'] = _wordField.text;
- request['password_new'] = _newField.text;
- Map dict = await ysRequestHttp(context, requestType.post, 'i/changePassword', request);
- if(dict!=null){
- ysFlutterToast(context, '密码已更改请重新登陆');
- SharedPreferences _perfer = await SharedPreferences.getInstance();
- _perfer.remove('token');
- Navigator.pushAndRemoveUntil(context, MaterialPageRoute(
- builder: (context){
- return YSLogin(isCheck: true,);
- }
- ), (route) => false);
- }
- },
- child: Container(
- child: Text('提交',style: TextStyle(fontSize: 15,color: Colors.white,decoration: TextDecoration.none,fontWeight: FontWeight.w600),),
- height: 40,
- width: 40,
- alignment: Alignment.center,
- )
- ),
- ystitle: '修改密码',
- yschild: ListView.separated(
- padding: EdgeInsets.only(left: 20,right: 20,top: 20,bottom: 20),
- itemBuilder: (context,index){
- Map item = _showArray[index];
- return Container(
- child: LayoutBuilder(
- builder: (context,conSize){
- return Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- Text(item['title'],style: TextStyle(fontSize: 12,color: Color(0xFF808080),decoration: TextDecoration.none,fontWeight: FontWeight.w600),),
- Container(
- height: 40,
- margin: EdgeInsets.only(top: 10),
- width: conSize.maxWidth,
- child: CupertinoTextField(
- placeholder: '请输入',
- style: TextStyle(fontSize: 12,color: Color(0xFF808080)),
- controller: item['title']=='旧密码'?_passField:item['title']=='再次输入新密码'?_wordField:_newField,
- obscureText: item['isObscure'],
- suffix: GestureDetector(
- onTap: (){
- item['isObscure'] = !item['isObscure'];
- setState(() {});
- },
- child: Padding(
- padding: EdgeInsets.only(right: 10),
- child: Image.asset('lib/images/${item['isObscure']==true?'eye-slash':'eye'}.png',height: 15,width: 15,)
- ),
- ),
- ),
- )
- ],
- );
- },
- ),
- );
- },
- separatorBuilder: (context,index){
- return Container(height: 20,);
- },
- itemCount: _showArray.length
- ),
- );
- }
- }
|