import 'package:flutter/material.dart'; import 'package:huixiang/view_widget/my_appbar.dart'; import 'package:pull_to_refresh/pull_to_refresh.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; import '../../utils/font_weight.dart'; import '../../view_widget/classic_header.dart'; import '../../view_widget/my_footer.dart'; class SecuritySetting extends StatefulWidget { @override State createState() { return _SecuritySetting(); } } class _SecuritySetting extends State { final RefreshController refreshController = RefreshController(); int pageState = 1; final TextEditingController newPasswordController = TextEditingController(); final TextEditingController oldPasswordController = TextEditingController(); FocusNode _focusNode = FocusNode(); bool isKeyBoardShow = false; @override void initState() { super.initState(); WidgetsBinding.instance.addPostFrameCallback((_) { setState(() { print("object: ${MediaQuery.of(context).viewInsets.bottom}"); if (MediaQuery.of(context).viewInsets.bottom == 0) { if (isKeyBoardShow) { isKeyBoardShow = false; //关闭键盘 软键盘关闭了, 清除输入控件的焦点, 否则重新进入页面会导致软键盘再弹出问题 FocusScope.of(context).requestFocus(FocusNode()); } } else { isKeyBoardShow = true; } }); }); } ///离开页面记着销毁和清除 @override void dispose() { _focusNode.unfocus(); super.dispose(); } @override Widget build(BuildContext context) { return GestureDetector( behavior: HitTestBehavior.opaque, onTap: (){ FocusScope.of(context).requestFocus(FocusNode()); }, child: Scaffold( backgroundColor: Color(0xFFF8F8FA), appBar: MyAppBar( title: pageState == 1 ?"安全设置": "修改登录密码", titleColor: Colors.black, background: Colors.white, leadingColor: Colors.black, brightness: Brightness.dark, ), body: SmartRefresher( controller: refreshController, enablePullDown: true, enablePullUp: false, header: MyHeader( color: Colors.white, ), footer: CustomFooter( builder: (context, mode) { return MyFooter(mode); }, ), onRefresh: () { }, physics: BouncingScrollPhysics(), scrollController: ScrollController(), child: SingleChildScrollView( physics: BouncingScrollPhysics(), child:Container( margin: EdgeInsets.only(top: 24.h,left: 16.w,right: 16.w), child:Column( children: [ if(pageState == 1) Container( decoration: BoxDecoration( color: Colors.white, borderRadius: BorderRadius.circular(8.w), boxShadow: [ BoxShadow( color: Color(0x0F06152E).withAlpha(12), offset: Offset(0, 2), blurRadius: 4, spreadRadius: 0, ), ], ), padding: EdgeInsets.only(top: 16.h,left: 16.w,right: 16.w,), child: Column( children: [ Row( children: [ Expanded(child:Text( "登录手机号", style: TextStyle( fontSize: 14.sp, color: Color(0xFF808080), fontWeight: MyFontWeight.medium),)), Text( "134****7777", maxLines: 2, overflow: TextOverflow.ellipsis, textAlign: TextAlign.right, style: TextStyle( fontSize: 14.sp, color: Color(0xFF1A1A1A), fontWeight: MyFontWeight.medium),), ], ), Container( height: 1.h, width: double.infinity, color: Color(0xFFEBECEF), margin: EdgeInsets.only(top:16.h,bottom: 16.h), ), GestureDetector( behavior: HitTestBehavior.opaque, onTap: (){ setState((){ pageState = 2; }); }, child: Row( children: [ Expanded(child:Text( "修改登录密码", style: TextStyle( fontSize: 14.sp, color: Color(0xFF808080), fontWeight: MyFontWeight.medium),)), Image.asset( "assets/image/icon_right_z.webp", width: 16, height:16, color: Color(0xFF353535), ), ], ), ), Container( height: 1.h, width: double.infinity, color: Color(0xFFEBECEF), margin: EdgeInsets.only(top:16.h,bottom: 16.h), ), ], ), ), if(pageState == 2) changePassword(), if(pageState == 2) GestureDetector( behavior: HitTestBehavior.opaque, onTap: (){ setState((){ pageState = 1; }); }, child: Container( width: double.infinity, alignment: Alignment.center, margin: EdgeInsets.only(bottom:55.h,top: 36.h), padding: EdgeInsets.symmetric(vertical:16.h), decoration: BoxDecoration( borderRadius: BorderRadius.circular(27), color: Color(0xFF30415B) ), child: Text( "确认修改", style: TextStyle( fontWeight: MyFontWeight.semi_bold, fontSize: 16.sp, color: Colors.white, ), ), ), ) ], ), ), ), ), ), ); } Widget changePassword(){ return Container( decoration: BoxDecoration( color: Colors.white, borderRadius: BorderRadius.circular(8.w), boxShadow: [ BoxShadow( color: Color(0x0F06152E).withAlpha(12), offset: Offset(0, 2), blurRadius: 4, spreadRadius: 0, ), ], ), padding: EdgeInsets.only(top: 16.h,left: 16.w,right: 16.w,), child: Column( children: [ Row( children: [ Text( "旧密码", style: TextStyle( fontSize: 14.sp, color: Color(0xFF808080), fontWeight: MyFontWeight.medium),), Expanded( child: TextField( controller: oldPasswordController, decoration: InputDecoration( hintText: "请输入旧密码", hintStyle: TextStyle( color: Color(0xFF808080), fontSize: 14.sp, fontWeight: MyFontWeight.regular ), border: InputBorder.none, contentPadding: EdgeInsets.only(left: 16.w), ), keyboardType: TextInputType.phone, style: TextStyle( color: Color(0xFF808080), fontSize: 14.sp, fontWeight: MyFontWeight.regular ), ), ), ], ), Container( height: 1.h, width: double.infinity, color: Color(0xFFEBECEF), margin: EdgeInsets.only(bottom: 16.h), ), Row( children: [ Text( "新密码", style: TextStyle( fontSize: 14.sp, color: Color(0xFF808080), fontWeight: MyFontWeight.medium),), Expanded( child: TextField( controller: newPasswordController, decoration: InputDecoration( hintText: "请输入新密码", hintStyle: TextStyle( color: Color(0xFF808080), fontSize: 14.sp, fontWeight: MyFontWeight.regular ), border: InputBorder.none, contentPadding: EdgeInsets.only(left: 16.w), ), keyboardType: TextInputType.phone, style: TextStyle( color: Color(0xFF808080), fontSize: 14.sp, fontWeight: MyFontWeight.regular ), ), ), ], ), Container( height: 1.h, width: double.infinity, color: Color(0xFFEBECEF), margin: EdgeInsets.only(bottom: 16.h), ), ], ), ); } }