You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
173 lines
6.1 KiB
Dart
173 lines
6.1 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter_svg/svg.dart';
|
|
import 'package:tangheem/api/user_api_client.dart';
|
|
import 'package:tangheem/classes/colors.dart';
|
|
import 'package:tangheem/classes/utils.dart';
|
|
import 'package:tangheem/extensions/int_extensions.dart';
|
|
import 'package:tangheem/extensions/string_extensions.dart';
|
|
import 'package:tangheem/extensions/widget_extensions.dart';
|
|
import 'package:tangheem/ui/screens/contact_us_screen.dart';
|
|
import 'package:tangheem/widgets/common_textfield_widget.dart';
|
|
|
|
class ForgotPasswordScreen extends StatefulWidget {
|
|
static const String routeName = "/forgot_password";
|
|
|
|
ForgotPasswordScreen({Key key}) : super(key: key);
|
|
|
|
@override
|
|
_ForgotPasswordScreenState createState() {
|
|
return _ForgotPasswordScreenState();
|
|
}
|
|
}
|
|
|
|
class _ForgotPasswordScreenState extends State<ForgotPasswordScreen> {
|
|
TextEditingController _emailController = TextEditingController();
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
}
|
|
|
|
@override
|
|
void dispose() {
|
|
super.dispose();
|
|
}
|
|
|
|
void forgotPassword(String email) async {
|
|
Utils.showLoading(context);
|
|
try {
|
|
await UserApiClient().forgotPassword(email);
|
|
Utils.showToast("تم إرسال رابط تغيير كلمة المرور إلى بريدك الإلكتروني");
|
|
} catch (ex) {
|
|
if (mounted) Utils.handleException(ex, null);
|
|
Utils.hideLoading(context);
|
|
return;
|
|
} finally {
|
|
Utils.hideLoading(context);
|
|
}
|
|
//getOTP(email);
|
|
}
|
|
|
|
void verifyOTP(String email, int otp) async {
|
|
Utils.showLoading(context);
|
|
try {
|
|
await UserApiClient().verifyOTP(email, otp);
|
|
} catch (ex) {
|
|
if (mounted) Utils.handleException(ex, null);
|
|
Utils.hideLoading(context);
|
|
return;
|
|
} finally {
|
|
Utils.hideLoading(context);
|
|
}
|
|
Navigator.pop(context);
|
|
//changePassword(email, otp);
|
|
}
|
|
|
|
void updatePassword(String email, int otp, String password) async {
|
|
Utils.showLoading(context);
|
|
try {
|
|
//await UserApiClient().updatePassword(email, otp, password);
|
|
} catch (ex) {
|
|
if (mounted) Utils.handleException(ex, null);
|
|
Utils.hideLoading(context);
|
|
return;
|
|
} finally {
|
|
Utils.hideLoading(context);
|
|
}
|
|
Navigator.pop(context);
|
|
Utils.showToast("تم تغيير كلمة المرور بنجاح");
|
|
Navigator.pop(context);
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
backgroundColor: ColorConsts.greyF8Color,
|
|
body: SingleChildScrollView(
|
|
padding: EdgeInsets.only(top: 100, bottom: 24, left: 24, right: 24),
|
|
physics: BouncingScrollPhysics(),
|
|
child: Column(
|
|
children: [
|
|
Image.asset("assets/icons/new/Tangeem-logo.png", width: 116, height: 62),
|
|
30.height,
|
|
Container(
|
|
width: MediaQuery.of(context).size.width,
|
|
decoration: BoxDecoration(borderRadius: BorderRadius.circular(20.0), color: Colors.white),
|
|
margin: EdgeInsets.only(top: 6, bottom: 20),
|
|
padding: EdgeInsets.only(top: 50, bottom: 20, left: 11, right: 11),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.center,
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
SvgPicture.asset("assets/icons/key.svg", width: 100, height: 72),
|
|
25.height,
|
|
"استعادة كلمة المرور".toText(18, color: ColorConsts.darkText),
|
|
18.height,
|
|
"يمكنك إعادة تعيين كلمة المرور عبر حساب بريدك الإلكتروني".toText(13, color: ColorConsts.grey9FColor, textAlign: TextAlign.center).paddingOnly(left: 77, right: 77),
|
|
25.height,
|
|
CommonTextFieldWidget(hint: "البريد الإلكتروني المسجل", controller: _emailController, isEmail: true),
|
|
],
|
|
),
|
|
),
|
|
SizedBox(
|
|
width: double.infinity,
|
|
height: 50,
|
|
child: TextButton(
|
|
onPressed: () {
|
|
if (_emailController.text.length < 1) {
|
|
Utils.showToast("يرجى إدخال البريد الإلكتروني");
|
|
return;
|
|
} else if (!_emailController.text.isValidEmail()) {
|
|
Utils.showToast("صيغة البريد الإلكتروني خاطئة");
|
|
return;
|
|
}
|
|
forgotPassword(_emailController.text);
|
|
},
|
|
style: TextButton.styleFrom(
|
|
backgroundColor: ColorConsts.darkText,
|
|
foregroundColor: Colors.white,
|
|
textStyle: TextStyle(fontSize: 18),
|
|
shape: RoundedRectangleBorder(
|
|
borderRadius: BorderRadius.circular(25.0),
|
|
),
|
|
),
|
|
child: Text("إعادة تعيين كلمة المرور"),
|
|
),
|
|
).paddingOnly(left: 11, right: 11, bottom: 28),
|
|
Column(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
SvgPicture.asset("assets/icons/new/contact_us.svg", width: 26, height: 24, color: ColorConsts.greyC4Color),
|
|
8.height,
|
|
"اتصل بنا".toText(14, color: ColorConsts.greyC4Color),
|
|
],
|
|
).onPress(() {
|
|
Navigator.pushNamed(context, ContactUsScreen.routeName);
|
|
})
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
// void getOTP(String email) {
|
|
// showDialog(
|
|
// context: context,
|
|
// barrierColor: ColorConsts.secondaryWhite.withOpacity(0.8),
|
|
// builder: (BuildContext context) => OTPDialog(
|
|
// onOTP: (otp) => verifyOTP(email, otp),
|
|
// ),
|
|
// );
|
|
// }
|
|
//
|
|
// void changePassword(String email, int otp) {
|
|
// showDialog(
|
|
// context: context,
|
|
// barrierColor: ColorConsts.secondaryWhite.withOpacity(0.8),
|
|
// builder: (BuildContext context) => ChangePasswordDialog(
|
|
// onPassword: (password) => updatePassword(email, otp, password),
|
|
// ),
|
|
// );
|
|
// }
|
|
}
|