I want user to type in their password before they delete their acc. And I want the app to validate that password If its match the old password, How can I do it (this is my code so far)
_deleteAcc(String _password) async {
try {
await auth.checkActionCode(_password);
//Success
FirebaseAuth.instance.currentUser?.delete();
Navigator.pushAndRemoveUntil(
context,
MaterialPageRoute(builder: (_) => const LoginScreen()),
(route) => false);
Fluttertoast.showToast(
msg: 'Your account has been deleted',
gravity: ToastGravity.TOP,
toastLength: Toast.LENGTH_LONG, //duration 5sec
backgroundColor: Colors.grey[400],
textColor: Colors.black,
);
} on FirebaseAuthException {
Fluttertoast.showToast(
msg: 'Password not correct',
gravity: ToastGravity.TOP,
toastLength: Toast.LENGTH_LONG, //duration 5sec
backgroundColor: Colors.grey[400],
textColor: Colors.black,
);
}
Future openDialog() => showDialog(
context: context,
builder: (context) => AlertDialog(
title: const Text('Are you sure? '),
content: Form(
autovalidateMode: AutovalidateMode.always,
child: TextFormField(
decoration: const InputDecoration(hintText: 'Confirm
Password'),
validator: (value) => validatePassword(value),
obscureText: false,
onChanged: (value) {
setState(() {
_password = value.trim();
});
},
),
),
actions: [
OutlinedButton(
onPressed: (() => _deleteAcc(_password)),
child: const Text(
'Continue',
style: TextStyle(color: Colors.redAccent, fontSize:
17.0),
),
style: OutlinedButton.styleFrom(
side: const BorderSide(width: 5.0, color: Colors.transparent),
),
),
The continue button call in the _delete Acc method