import 'package:cathaypay_mobile/Home/HomePage.dart'; import 'package:cathaypay_mobile/Home/all_menu.dart'; import 'package:easy_localization/easy_localization.dart'; import 'package:flutter/material.dart'; import 'package:google_fonts/google_fonts.dart'; import 'package:cathaypay_mobile/PinCode.dart'; import 'package:easy_localization/easy_localization.dart'; import 'package:flutter/cupertino.dart'; import 'dart:convert'; import 'dart:io'; import 'package:easy_localization/easy_localization.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import '../api/api.dart'; import '../utils/color_custom.dart'; import '../utils/utils.dart'; import 'dart:convert'; import 'dart:io'; import 'package:cathaypay_mobile/Login/forgot_password.dart'; import 'package:cathaypay_mobile/PinCode.dart'; import 'package:cathaypay_mobile/model/token_model.dart'; import 'package:cathaypay_mobile/utils/utils.dart'; import 'package:device_info_plus/device_info_plus.dart'; import 'package:easy_localization/easy_localization.dart'; import 'package:flutter/material.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart'; import 'package:google_fonts/google_fonts.dart'; import 'package:package_info_plus/package_info_plus.dart'; import 'package:shared_preferences/shared_preferences.dart'; import '../api/api.dart'; import '../utils/color_custom.dart'; TextEditingController _current_pass = TextEditingController(); TextEditingController _new_pass = TextEditingController(); TextEditingController _confirm_pass = TextEditingController(); class ChangePasswordPage extends StatefulWidget { const ChangePasswordPage({super.key}); @override State createState() => _ChangePasswordPageState(); } class _ChangePasswordPageState extends State { AndroidDeviceInfo? androidDeviceInfo; IosDeviceInfo? iosDeviceInfo; ChangePassword() async { // print(_current_email.text); // print(_new_email.text); if (_current_pass.text.isNotEmpty &&_new_pass.text == _confirm_pass.text) { var device = ""; if (Platform.isAndroid) { device = androidDeviceInfo?.id ?? ""; } else if (Platform.isIOS) { device = iosDeviceInfo?.name ?? ""; } var param = jsonEncode({ "mobileDeviceID": device, "oldPassword": _current_pass.text, "newPassword": _new_pass.text, "confirmPassword": _confirm_pass.text }); Api.post(context, Api.changePassword, param).then((value) => { if (value != null) { // initQrCode(value) Utils.showAlertDialogCallback( context, "บันทึกสำเร็จ", (value) { Navigator.pushNamed(context, '/HomePage'); }, ) } else {} }); } } @override Widget build(BuildContext context) { return Scaffold( // extendBodyBehindAppBar: true, appBar: AppBar( backgroundColor: Colors.white, leading: CupertinoButton( onPressed: () { Navigator.pop(context); }, child: const Icon( Icons.arrow_back, color: Colors.black54, ), ), elevation: 0, centerTitle: true, title: Text( "เปลี่ยนอีเมล".tr(), textAlign: TextAlign.center, style: GoogleFonts.kanit( color: Colors.black, fontSize: 20, ), ), ), body: SafeArea( child: Padding( padding: const EdgeInsets.all(20.0), child: Container(height: MediaQuery.of(context).size.height, child: Column(mainAxisSize: MainAxisSize.max, crossAxisAlignment: CrossAxisAlignment.start, children: [ SizedBox( height: 10, ), Text( "รหัสผ่านปัจจุบัน".tr(), style: GoogleFonts.kanit( color: Color(0xff565656), fontSize: 15, ), ), SizedBox( height: 10, ), Container( child: TextField( keyboardType: TextInputType.emailAddress, // inputFormatters: [ // FilteringTextInputFormatter.allow(RegExp(r'[0-9]')), // ], controller: _current_pass, decoration: InputDecoration( // hintText: 'อีเมลปัจจุบัน'.tr(), border: InputBorder.none, contentPadding: EdgeInsets.symmetric(horizontal: 16), ), ), // margin: EdgeInsets.symmetric(horizontal: 20), height: 48, decoration: BoxDecoration( borderRadius: BorderRadius.circular(100), color: Color(0xfff2f2f2), ), ), SizedBox( height: 10, ), Text( "รหัสผ่านใหม่".tr(), style: GoogleFonts.kanit( color: Color(0xff565656), fontSize: 15, ), ), SizedBox( height: 10, ), Container( child: TextField( keyboardType: TextInputType.emailAddress, // inputFormatters: [ // FilteringTextInputFormatter.allow(RegExp(r'[0-9]')), // ], controller: _new_pass, decoration: InputDecoration( // hintText: 'อีเมลปัจจุบัน'.tr(), border: InputBorder.none, contentPadding: EdgeInsets.symmetric(horizontal: 16), ), ), // margin: EdgeInsets.symmetric(horizontal: 20), height: 48, decoration: BoxDecoration( borderRadius: BorderRadius.circular(100), color: Color(0xfff2f2f2), ), ), SizedBox( height: 10, ), Text( "กรอกรหัสผ่านใหม่อีกครั้ง".tr(), style: GoogleFonts.kanit( color: Color(0xff565656), fontSize: 15, ), ), SizedBox( height: 10, ), Container( child: TextField( keyboardType: TextInputType.emailAddress, // inputFormatters: [ // FilteringTextInputFormatter.allow(RegExp(r'[0-9]')), // ], controller: _confirm_pass, decoration: InputDecoration( // hintText: 'อีเมลปัจจุบัน'.tr(), border: InputBorder.none, contentPadding: EdgeInsets.symmetric(horizontal: 16), ), ), // margin: EdgeInsets.symmetric(horizontal: 20), height: 48, decoration: BoxDecoration( borderRadius: BorderRadius.circular(100), color: Color(0xfff2f2f2), ), ), Spacer(), // Expanded(child: Container()), InkWell( onTap: () async { /* String pattern = r'^(?=.*?[a-z])(?=.*?[0-9]).{6,}$'; RegExp regExp = RegExp(pattern); if (!regExp.hasMatch(_new_pass.text)) { Utils.showAlertDialog(context, "Password ต้องมีตัวเลขและตัวอักษรภาษาอังกฤษอย่างน้อย 1 ตัว".tr()); return; } if (_new_pass.text.length < 6) { Utils.showAlertDialog(context, "Password ต้องมากกว่า 6 ตัว".tr()); return; } if (_new_pass.text != _confirm_pass.text) { Utils.showAlertDialog(context, "Password ไม่ตรงกัน".tr()); return; }*/ ChangePassword(); }, child: Container( width: double.infinity, child: Card( shape: RoundedRectangleBorder( borderRadius: BorderRadius.circular(40), ), child: Container( padding: EdgeInsets.all(10), child: Text( "Confirm".tr(), textAlign: TextAlign.center, style: GoogleFonts.kanit( color: ColorCustom.greyBorder, fontSize: 20, fontWeight: FontWeight.w500, ), ), ), ), ), ) ]), )))); } }