설명 없음
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.

forgotPassword_screen.dart 12KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312
  1. import 'dart:convert';
  2. import 'package:flutter/material.dart';
  3. import 'package:fluttertoast/fluttertoast.dart';
  4. import 'package:google_fonts/google_fonts.dart';
  5. import 'package:employee_selfservice_mobile/Screens/ForgotPassword/resetPassword_post.dart';
  6. import 'package:employee_selfservice_mobile/Screens/Login/background.dart';
  7. import 'package:employee_selfservice_mobile/Screens/Login/inputWidget.dart';
  8. import 'package:employee_selfservice_mobile/Screens/Login/login_screen.dart';
  9. import 'package:progress_dialog_null_safe/progress_dialog_null_safe.dart';
  10. class ForgotPasswordView extends StatefulWidget {
  11. @override
  12. _ForgotPasswordView createState() => _ForgotPasswordView();
  13. }
  14. class _ForgotPasswordView extends State<ForgotPasswordView> {
  15. @override
  16. Widget build(BuildContext context) {
  17. return Scaffold(
  18. resizeToAvoidBottomInset: false,
  19. backgroundColor: Colors.white,
  20. body: Stack(
  21. children: <Widget>[
  22. Background(),
  23. ForgotPasswordScreen(),
  24. ],
  25. ));
  26. }
  27. }
  28. class ForgotPasswordScreen extends StatelessWidget {
  29. const ForgotPasswordScreen({Key? key}) : super(key: key);
  30. @override
  31. Widget build(BuildContext context) {
  32. ProgressDialog loading = ProgressDialog(context);
  33. loading = ProgressDialog(context,
  34. type: ProgressDialogType.normal, isDismissible: false, showLogs: true);
  35. loading.style(
  36. message: 'Please Wait .....',
  37. borderRadius: 5,
  38. backgroundColor: Colors.white,
  39. progressWidget: CircularProgressIndicator(),
  40. elevation: 10.0,
  41. padding: EdgeInsets.all(10),
  42. insetAnimCurve: Curves.easeInOut,
  43. progress: 0.0,
  44. maxProgress: 100.0,
  45. progressTextStyle: TextStyle(
  46. color: Colors.black, fontSize: 10.0, fontWeight: FontWeight.w400),
  47. messageTextStyle: TextStyle(
  48. color: Colors.black, fontSize: 15.0, fontWeight: FontWeight.w600));
  49. return Column(
  50. children: <Widget>[
  51. Padding(
  52. padding:
  53. EdgeInsets.only(top: MediaQuery.of(context).size.height / 2.45),
  54. ),
  55. Column(
  56. children: <Widget>[
  57. Column(
  58. crossAxisAlignment: CrossAxisAlignment.center,
  59. children: <Widget>[
  60. Padding(
  61. padding: EdgeInsets.only(top: 0),
  62. child: Text(
  63. "Forgot Password",
  64. style: GoogleFonts.knewave(
  65. color: Colors.blueAccent, fontSize: 25),
  66. ),
  67. ),
  68. ],
  69. ),
  70. Column(
  71. crossAxisAlignment: CrossAxisAlignment.start,
  72. children: <Widget>[
  73. Padding(
  74. padding: EdgeInsets.only(left: 40, bottom: 5, top: 20),
  75. child: Text(
  76. "Email",
  77. style: TextStyle(fontSize: 16, color: Colors.black87),
  78. ),
  79. ),
  80. Stack(
  81. alignment: Alignment.bottomRight,
  82. children: <Widget>[
  83. InputWidgetEmail(20.0, 20.0),
  84. Padding(
  85. padding: EdgeInsets.only(right: 15),
  86. child: Row(
  87. children: <Widget>[
  88. Expanded(
  89. child: Padding(
  90. padding: EdgeInsets.only(top: 0),
  91. )),
  92. InkWell(
  93. child: Container(
  94. padding: EdgeInsets.all(10),
  95. decoration: ShapeDecoration(
  96. shape: CircleBorder(),
  97. gradient: LinearGradient(
  98. colors: Gradients2,
  99. begin: Alignment.topLeft,
  100. end: Alignment.bottomRight),
  101. ),
  102. child: ImageIcon(
  103. AssetImage("assets/images/ic_forward.png"),
  104. size: 40,
  105. color: Colors.white,
  106. ),
  107. ),
  108. onTap: () async {
  109. if (emailController.text.toString().isEmpty){
  110. Fluttertoast.showToast(
  111. msg: "Email Required",
  112. toastLength: Toast.LENGTH_SHORT,
  113. gravity: ToastGravity.CENTER,
  114. timeInSecForIosWeb: 1,
  115. textColor: Colors.white,
  116. fontSize: 16.0);
  117. } else {
  118. await loading.show();
  119. ResetPassword_Post.connectToAPI(emailController.text.toString())
  120. .then((valueResult) async{
  121. Map<String, dynamic> object = json.decode(valueResult);
  122. if (object.containsKey("result").toString() == "true") {
  123. String status = object['result']['status'].toString();
  124. String message = object['result']['message'].toString();
  125. if (status == "success") {
  126. emailController.clear();
  127. await loading.hide();
  128. Widget okButton = TextButton(
  129. child: Text("OK"),
  130. onPressed: () {
  131. Navigator.of(context, rootNavigator: true).pop();
  132. Navigator.pushAndRemoveUntil(
  133. context,
  134. MaterialPageRoute(
  135. builder: (context) => LoginView()),
  136. (route) => false);
  137. },
  138. );
  139. // set up the AlertDialog
  140. AlertDialog alert = AlertDialog(
  141. title: Text("Employee Self Service"),
  142. //content: Text(message),
  143. content: Text("Link to reset password has been sent to your email address"),
  144. actions: [
  145. okButton,
  146. ],
  147. );
  148. // show the dialog
  149. showDialog(
  150. context: context,
  151. barrierDismissible: false,
  152. builder: (BuildContext context) {
  153. return alert;
  154. },
  155. );
  156. } else if (status == "failed") {
  157. await loading.hide();
  158. Widget okButton = TextButton(
  159. child: Text("Back"),
  160. onPressed: () {
  161. Navigator.of(context, rootNavigator: true).pop();
  162. },
  163. );
  164. // set up the AlertDialog
  165. AlertDialog alert = AlertDialog(
  166. title: Text("Employee Self Service"),
  167. //content: Text(message),
  168. content: Text("Your email has not been registered"),
  169. actions: [
  170. okButton,
  171. ],
  172. );
  173. // show the dialog
  174. showDialog(
  175. context: context,
  176. barrierDismissible: false,
  177. builder: (BuildContext context) {
  178. return alert;
  179. },
  180. );
  181. /*Fluttertoast.showToast(
  182. msg: message,
  183. toastLength: Toast.LENGTH_SHORT,
  184. gravity: ToastGravity.CENTER,
  185. timeInSecForIosWeb: 1,
  186. textColor: Colors.white,
  187. fontSize: 16.0);*/
  188. }
  189. } else {
  190. Fluttertoast.showToast(
  191. msg: "Server Response Error",
  192. toastLength: Toast.LENGTH_SHORT,
  193. gravity: ToastGravity.CENTER,
  194. timeInSecForIosWeb: 1,
  195. textColor: Colors.white,
  196. fontSize: 16.0);
  197. await loading.hide();
  198. }
  199. });
  200. }
  201. },
  202. )
  203. ],
  204. ),
  205. ),
  206. ],
  207. ),
  208. ],
  209. ),
  210. Padding(
  211. padding: EdgeInsets.only(bottom: 10),
  212. ),
  213. ],
  214. )
  215. ],
  216. );
  217. }
  218. }
  219. Widget roundedRectButton(
  220. String title, List<Color> gradient, bool isEndIconVisible) {
  221. return Builder(builder: (BuildContext mContext) {
  222. return Align(
  223. alignment: Alignment.centerLeft,
  224. child: Stack(
  225. children: <Widget>[
  226. Container(
  227. alignment: Alignment.centerRight,
  228. width: MediaQuery.of(mContext).size.width / 2.5,
  229. decoration: ShapeDecoration(
  230. shape: RoundedRectangleBorder(
  231. borderRadius: BorderRadius.only(
  232. topRight: Radius.circular(20.0),
  233. bottomRight: Radius.circular(20.0))),
  234. gradient: LinearGradient(
  235. colors: gradient,
  236. begin: Alignment.topLeft,
  237. end: Alignment.bottomRight),
  238. ),
  239. child: Text(title,
  240. style: TextStyle(
  241. color: Colors.white,
  242. fontSize: 15,
  243. fontWeight: FontWeight.w500)),
  244. padding: EdgeInsets.all(10),
  245. ),
  246. Visibility(
  247. visible: isEndIconVisible,
  248. child: Padding(
  249. padding: EdgeInsets.only(right: 10),
  250. child: ImageIcon(
  251. AssetImage("assets/images/ic_forward.png"),
  252. size: 30,
  253. color: Colors.white,
  254. )),
  255. ),
  256. ],
  257. ),
  258. );
  259. });
  260. }
  261. //Alert Dialog
  262. showAlertDialog(BuildContext context) {
  263. // set up the button
  264. Widget okButton = TextButton(
  265. child: Text("OK"),
  266. onPressed: () {
  267. Navigator.of(context, rootNavigator: true).pop();
  268. Navigator.pushAndRemoveUntil(
  269. context,
  270. MaterialPageRoute(
  271. builder: (context) => LoginView()),
  272. (route) => false);
  273. },
  274. );
  275. // set up the AlertDialog
  276. AlertDialog alert = AlertDialog(
  277. title: Text("Employee Self Service"),
  278. content: Text("Please check your email."),
  279. actions: [
  280. okButton,
  281. ],
  282. );
  283. // show the dialog
  284. showDialog(
  285. context: context,
  286. barrierDismissible: false,
  287. builder: (BuildContext context) {
  288. return alert;
  289. },
  290. );
  291. }
  292. const List<Color> Gradients1 = [
  293. Color(0xFF0EDED2),
  294. Color(0xFF03A0FE),
  295. ];
  296. const List<Color> Gradients2 = [
  297. Color(0xFFFF9945),
  298. Color(0xFFFc6076),
  299. ];