2022-04-29 09:10:21 +02:00
|
|
|
import 'package:lottie/lottie.dart';
|
2022-05-16 02:51:47 +02:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
2022-05-15 12:48:35 +02:00
|
|
|
import 'package:nekoya_flutter/api/api.dart';
|
2022-04-29 09:10:21 +02:00
|
|
|
import 'package:nekoya_flutter/screens/otp.dart';
|
|
|
|
|
|
|
|
class ForgotPassBody extends StatefulWidget {
|
|
|
|
const ForgotPassBody({Key? key}) : super(key: key);
|
|
|
|
|
|
|
|
@override
|
|
|
|
State<ForgotPassBody> createState() => _ForgotPassBodyState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _ForgotPassBodyState extends State<ForgotPassBody> {
|
2022-05-15 12:48:35 +02:00
|
|
|
TextEditingController emailController = TextEditingController();
|
|
|
|
|
2022-05-21 12:50:11 +02:00
|
|
|
Future forgotForm(BuildContext context) async {
|
|
|
|
if (emailController.text.isEmpty) {
|
|
|
|
return 999;
|
|
|
|
} else {
|
|
|
|
Map<String, dynamic> data = {
|
|
|
|
"email": emailController.text,
|
|
|
|
};
|
|
|
|
|
|
|
|
var response = await resetPost(data);
|
|
|
|
return {'statusCode': response['statusCode'], 'data': response['data']};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-29 09:10:21 +02:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return Container(
|
2022-04-29 11:36:42 +02:00
|
|
|
padding: const EdgeInsets.all(25),
|
2022-04-29 09:10:21 +02:00
|
|
|
child: ListView(
|
|
|
|
children: [
|
|
|
|
Container(
|
2022-05-16 02:53:52 +02:00
|
|
|
child: Lottie.asset('assets/lottie/forgot_pass_body.json'),
|
2022-04-29 09:10:21 +02:00
|
|
|
),
|
|
|
|
Container(
|
2022-04-29 11:36:42 +02:00
|
|
|
padding: const EdgeInsets.only(top: 25),
|
|
|
|
child: const Text(
|
2022-04-29 09:10:21 +02:00
|
|
|
'Enter your email to receive instructions on how to reset your password.',
|
|
|
|
style: TextStyle(color: Colors.white),
|
|
|
|
textAlign: TextAlign.center,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
Container(
|
2022-04-29 11:36:42 +02:00
|
|
|
padding: const EdgeInsets.only(top: 25, bottom: 20),
|
2022-04-29 09:10:21 +02:00
|
|
|
child: Row(
|
2022-04-29 11:36:42 +02:00
|
|
|
children: const [
|
2022-04-29 09:10:21 +02:00
|
|
|
Icon(
|
|
|
|
Icons.mail_sharp,
|
|
|
|
color: Colors.white,
|
|
|
|
),
|
2022-05-15 21:19:36 +02:00
|
|
|
Text(' Email', style: TextStyle(color: Colors.white)),
|
2022-04-29 09:10:21 +02:00
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
Container(
|
2022-04-29 11:36:42 +02:00
|
|
|
padding: const EdgeInsets.only(bottom: 20),
|
2022-05-15 12:48:35 +02:00
|
|
|
child: TextField(
|
|
|
|
controller: emailController,
|
|
|
|
keyboardType: TextInputType.emailAddress,
|
2022-05-16 02:42:29 +02:00
|
|
|
style: const TextStyle(color: Colors.white),
|
2022-04-29 09:10:21 +02:00
|
|
|
decoration: InputDecoration(
|
2022-05-15 21:19:36 +02:00
|
|
|
focusedBorder: OutlineInputBorder(
|
|
|
|
borderSide: const BorderSide(
|
|
|
|
color: Colors.red,
|
|
|
|
),
|
|
|
|
borderRadius: BorderRadius.circular(10.0)),
|
|
|
|
enabledBorder: OutlineInputBorder(
|
|
|
|
borderSide: const BorderSide(
|
|
|
|
color: Colors.white60,
|
|
|
|
),
|
|
|
|
borderRadius: BorderRadius.circular(10.0)),
|
|
|
|
),
|
2022-04-29 09:10:21 +02:00
|
|
|
),
|
|
|
|
),
|
2022-04-29 11:36:42 +02:00
|
|
|
ElevatedButton(
|
|
|
|
style: ButtonStyle(
|
|
|
|
foregroundColor:
|
2022-04-29 14:59:47 +02:00
|
|
|
MaterialStateProperty.all(const Color(0xff8B0000)),
|
2022-04-29 11:36:42 +02:00
|
|
|
backgroundColor:
|
2022-04-29 14:59:47 +02:00
|
|
|
MaterialStateProperty.all(const Color(0xff8B0000)),
|
2022-04-29 11:36:42 +02:00
|
|
|
shape: MaterialStateProperty.all<RoundedRectangleBorder>(
|
|
|
|
RoundedRectangleBorder(
|
|
|
|
borderRadius: BorderRadius.circular(18.0),
|
2022-05-15 21:19:36 +02:00
|
|
|
side: const BorderSide(color: Colors.black)))),
|
2022-04-29 11:36:42 +02:00
|
|
|
onPressed: () {
|
2022-05-21 11:41:21 +02:00
|
|
|
if (emailController.text.isEmpty) {
|
|
|
|
showAlertDialog(context);
|
|
|
|
} else {
|
2022-05-21 12:50:11 +02:00
|
|
|
forgotForm(context).then((res) {
|
|
|
|
if (res['statusCode'] == 200) {
|
|
|
|
Navigator.push(context,
|
|
|
|
MaterialPageRoute(builder: (context) => const Otp()));
|
|
|
|
} else if (res['statusCode'] == 205) {
|
|
|
|
showEmailWarn(context);
|
|
|
|
} else {
|
|
|
|
showBad(context);
|
|
|
|
}
|
|
|
|
});
|
2022-05-21 11:41:21 +02:00
|
|
|
}
|
2022-04-29 11:36:42 +02:00
|
|
|
},
|
|
|
|
child: const Text(
|
|
|
|
'Reset Password',
|
|
|
|
style: TextStyle(color: Colors.white, fontSize: 20),
|
2022-04-29 09:10:21 +02:00
|
|
|
),
|
|
|
|
),
|
2022-04-29 11:36:42 +02:00
|
|
|
ElevatedButton(
|
|
|
|
style: ButtonStyle(
|
|
|
|
foregroundColor:
|
2022-04-29 14:59:47 +02:00
|
|
|
MaterialStateProperty.all(const Color(0xff8B0000)),
|
2022-04-29 11:36:42 +02:00
|
|
|
backgroundColor:
|
2022-04-29 14:59:47 +02:00
|
|
|
MaterialStateProperty.all(const Color(0xff8B0000)),
|
2022-04-29 11:36:42 +02:00
|
|
|
shape: MaterialStateProperty.all<RoundedRectangleBorder>(
|
|
|
|
RoundedRectangleBorder(
|
|
|
|
borderRadius: BorderRadius.circular(18.0),
|
2022-05-15 21:19:36 +02:00
|
|
|
side: const BorderSide(color: Colors.black)))),
|
2022-04-29 11:36:42 +02:00
|
|
|
onPressed: () {
|
2022-05-14 18:29:43 +02:00
|
|
|
Navigator.pushNamed(context, '/login');
|
2022-04-29 11:36:42 +02:00
|
|
|
},
|
|
|
|
child: const Text(
|
|
|
|
'Back to Login',
|
|
|
|
style: TextStyle(color: Colors.white, fontSize: 20),
|
2022-04-29 09:10:21 +02:00
|
|
|
),
|
|
|
|
)
|
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2022-05-21 11:41:21 +02:00
|
|
|
|
|
|
|
showAlertDialog(BuildContext context) {
|
|
|
|
Widget okButton = TextButton(
|
|
|
|
child: const Text("OK", style: TextStyle(color: Colors.red)),
|
|
|
|
onPressed: () {
|
|
|
|
Navigator.of(context, rootNavigator: true).pop();
|
|
|
|
},
|
|
|
|
);
|
|
|
|
AlertDialog alert = AlertDialog(
|
|
|
|
backgroundColor: const Color(0xff1b1c1e),
|
|
|
|
shape: RoundedRectangleBorder(
|
|
|
|
borderRadius: BorderRadius.circular(10),
|
|
|
|
),
|
|
|
|
title: const Text(
|
|
|
|
"Error",
|
|
|
|
style: TextStyle(color: Colors.white),
|
|
|
|
),
|
|
|
|
content: const Text(
|
2022-05-22 12:07:01 +02:00
|
|
|
"Please input your email !",
|
2022-05-21 12:50:11 +02:00
|
|
|
style: TextStyle(color: Colors.white70),
|
|
|
|
),
|
|
|
|
actions: [
|
|
|
|
okButton,
|
|
|
|
],
|
|
|
|
);
|
|
|
|
showDialog(
|
|
|
|
context: context,
|
|
|
|
builder: (BuildContext context) {
|
|
|
|
return alert;
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
showEmailWarn(BuildContext context) {
|
|
|
|
Widget okButton = TextButton(
|
|
|
|
child: const Text("OK", style: TextStyle(color: Colors.red)),
|
|
|
|
onPressed: () {
|
|
|
|
Navigator.of(context, rootNavigator: true).pop();
|
|
|
|
},
|
|
|
|
);
|
|
|
|
AlertDialog alert = AlertDialog(
|
|
|
|
backgroundColor: const Color(0xff1b1c1e),
|
|
|
|
shape: RoundedRectangleBorder(
|
|
|
|
borderRadius: BorderRadius.circular(10),
|
|
|
|
),
|
|
|
|
title: const Text(
|
|
|
|
"Error",
|
|
|
|
style: TextStyle(color: Colors.white),
|
|
|
|
),
|
|
|
|
content: const Text(
|
2022-05-22 12:07:01 +02:00
|
|
|
"Sorry, Make sure your email has been registered before !",
|
2022-05-21 12:50:11 +02:00
|
|
|
style: TextStyle(color: Colors.white70),
|
|
|
|
),
|
|
|
|
actions: [
|
|
|
|
okButton,
|
|
|
|
],
|
|
|
|
);
|
|
|
|
showDialog(
|
|
|
|
context: context,
|
|
|
|
builder: (BuildContext context) {
|
|
|
|
return alert;
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
showBad(BuildContext context) {
|
|
|
|
Widget okButton = TextButton(
|
|
|
|
child: const Text("OK", style: TextStyle(color: Colors.red)),
|
|
|
|
onPressed: () {
|
|
|
|
Navigator.of(context, rootNavigator: true).pop();
|
|
|
|
},
|
|
|
|
);
|
|
|
|
AlertDialog alert = AlertDialog(
|
|
|
|
backgroundColor: const Color(0xff1b1c1e),
|
|
|
|
shape: RoundedRectangleBorder(
|
|
|
|
borderRadius: BorderRadius.circular(10),
|
|
|
|
),
|
|
|
|
title: const Text(
|
|
|
|
"Error",
|
|
|
|
style: TextStyle(color: Colors.white),
|
|
|
|
),
|
|
|
|
content: const Text(
|
2022-05-22 12:07:01 +02:00
|
|
|
"Bad Connection",
|
2022-05-21 11:41:21 +02:00
|
|
|
style: TextStyle(color: Colors.white70),
|
|
|
|
),
|
|
|
|
actions: [
|
|
|
|
okButton,
|
|
|
|
],
|
|
|
|
);
|
|
|
|
showDialog(
|
|
|
|
context: context,
|
|
|
|
builder: (BuildContext context) {
|
|
|
|
return alert;
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|