You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

205 lines
7.9 KiB

import 'package:flutter/material.dart';
import 'package:healthcare_user/common/settings.dart';
class UpdatePin extends StatefulWidget {
const UpdatePin({Key? key}) : super(key: key);
@override
State<UpdatePin> createState() => _UpdatePinState();
}
class _UpdatePinState extends State<UpdatePin> {
bool isOldPinObscureText=true;
bool isConfirmObscureText=true;
bool isNewPinObscureText=true;
TextEditingController oldPinController = TextEditingController();
TextEditingController newPinController = TextEditingController();
TextEditingController confirmPinController = TextEditingController();
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppSettings.appBar('Update Pin'),
body: Padding(
padding: EdgeInsets.all(10),
child: Column(
children: [
Container(
child: TextFormField(
cursorColor: greyColor,
obscureText: isOldPinObscureText,
controller: oldPinController,
decoration: InputDecoration(
fillColor: Colors.white,
filled: true,
labelText: 'Enter old pin',
prefixIcon: const Icon(
Icons.lock,
color: greyColor,
),
labelStyle: const TextStyle(
color: Colors.black, //<-- SEE HERE
),
border: const OutlineInputBorder(
borderSide: BorderSide(color: primaryColor)),
focusedBorder: const OutlineInputBorder(
borderSide: BorderSide(color: primaryColor),
),
enabledBorder: const OutlineInputBorder(
borderSide: BorderSide(color: primaryColor),
),
suffixIcon: IconButton(
icon: Icon(
Icons.visibility_off_outlined,
color: isOldPinObscureText?greyColor:primaryColor,
),
onPressed: () {
setState(() {
isOldPinObscureText = !isOldPinObscureText;
});
},
),
),
),
),
SizedBox(height:MediaQuery.of(context).size.height * .01,),
Container(
child: TextFormField(
cursorColor: greyColor,
obscureText: isNewPinObscureText,
controller: newPinController,
decoration: InputDecoration(
fillColor: Colors.white,
filled: true,
labelText: 'Enter new pin',
prefixIcon: const Icon(
Icons.lock,
color: greyColor,
),
labelStyle: const TextStyle(
color: Colors.black, //<-- SEE HERE
),
border: const OutlineInputBorder(
borderSide: BorderSide(color: primaryColor)),
focusedBorder: const OutlineInputBorder(
borderSide: BorderSide(color: primaryColor),
),
enabledBorder: const OutlineInputBorder(
borderSide: BorderSide(color: primaryColor),
),
suffixIcon: IconButton(
icon: Icon(
Icons.visibility_off_outlined,
color: isNewPinObscureText?greyColor:primaryColor,
),
onPressed: () {
setState(() {
isNewPinObscureText = !isNewPinObscureText;
});
},
),
),
),
),
SizedBox(height:MediaQuery.of(context).size.height * .01,),
Container(
child: TextFormField(
cursorColor: greyColor,
obscureText: isConfirmObscureText,
controller: confirmPinController,
decoration: InputDecoration(
fillColor: Colors.white,
filled: true,
labelText: 'Confirm pin',
prefixIcon: const Icon(
Icons.lock,
color: greyColor,
),
labelStyle: const TextStyle(
color: Colors.black, //<-- SEE HERE
),
border: const OutlineInputBorder(
borderSide: BorderSide(color: primaryColor)),
focusedBorder: const OutlineInputBorder(
borderSide: BorderSide(color: primaryColor),
),
enabledBorder: const OutlineInputBorder(
borderSide: BorderSide(color: primaryColor),
),
suffixIcon: IconButton(
icon: Icon(
Icons.visibility_off_outlined,
color: isConfirmObscureText?greyColor:primaryColor,
),
onPressed: () {
setState(() {
isConfirmObscureText = !isConfirmObscureText;
});
},
),
),
),
),
SizedBox(height:MediaQuery.of(context).size.height * .04,),
Container(
width:double.infinity,
height: MediaQuery.of(context).size.height * .05,
child: ElevatedButton(
style: ElevatedButton.styleFrom(
primary: buttonColors, // background
onPrimary: Colors.black, // foreground
),
onPressed: () async{
if(oldPinController.text!=''&&newPinController.text!=''&&confirmPinController.text!=''){
if(newPinController.text==confirmPinController.text){
var payload = new Map<String, dynamic>();
payload["oldPassword"] = oldPinController.text.toString();
payload["newPassword"] = newPinController.text.toString();
payload["phone"] = AppSettings.phoneNumber;
payload["longitude"] = AppSettings.userLongitude;
payload["latitude"] = AppSettings.userLatitude;
bool updateStatus = await AppSettings.updatePin(payload);
try{
if (updateStatus) {
//Navigator.pop(context);
/*Navigator.push(
context,
MaterialPageRoute(builder: (context) => Dashboard()),
);*/
oldPinController.clear();
newPinController.clear();
confirmPinController.clear();
AppSettings.longSuccessToast("Password updated");
} else {
AppSettings.longFailedToast("Password not updated");
}
}
catch(exception){
print(exception);
AppSettings.longFailedToast("Password not updated");
}
}
else{
AppSettings.longFailedToast('Please check new pin and confirm pin');
}
}
else{
AppSettings.longFailedToast('Please enter valid details');
}
},
child: const Text('Update Pin'),
)),
],
),
),
);
}
}