No Description
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 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  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:hris_selfservice_mobile/Screens/ForgotPassword/resetPassword_post.dart';
  6. import 'package:hris_selfservice_mobile/Screens/Login/background.dart';
  7. import 'package:hris_selfservice_mobile/Screens/Login/inputWidget.dart';
  8. import 'package:hris_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. actions: [
  144. okButton,
  145. ],
  146. );
  147. // show the dialog
  148. showDialog(
  149. context: context,
  150. builder: (BuildContext context) {
  151. return alert;
  152. },
  153. );
  154. } else if (status == "failed") {
  155. String message = object['result']['message'].toString();
  156. Fluttertoast.showToast(
  157. msg: message,
  158. toastLength: Toast.LENGTH_SHORT,
  159. gravity: ToastGravity.CENTER,
  160. timeInSecForIosWeb: 1,
  161. textColor: Colors.white,
  162. fontSize: 16.0);
  163. await loading.hide();
  164. }
  165. } else {
  166. Fluttertoast.showToast(
  167. msg: "Server Response Error",
  168. toastLength: Toast.LENGTH_SHORT,
  169. gravity: ToastGravity.CENTER,
  170. timeInSecForIosWeb: 1,
  171. textColor: Colors.white,
  172. fontSize: 16.0);
  173. await loading.hide();
  174. }
  175. });
  176. }
  177. },
  178. )
  179. ],
  180. ),
  181. ),
  182. ],
  183. ),
  184. ],
  185. ),
  186. Padding(
  187. padding: EdgeInsets.only(bottom: 10),
  188. ),
  189. ],
  190. )
  191. ],
  192. );
  193. }
  194. }
  195. Widget roundedRectButton(
  196. String title, List<Color> gradient, bool isEndIconVisible) {
  197. return Builder(builder: (BuildContext mContext) {
  198. return Align(
  199. alignment: Alignment.centerLeft,
  200. child: Stack(
  201. children: <Widget>[
  202. Container(
  203. alignment: Alignment.centerRight,
  204. width: MediaQuery.of(mContext).size.width / 2.5,
  205. decoration: ShapeDecoration(
  206. shape: RoundedRectangleBorder(
  207. borderRadius: BorderRadius.only(
  208. topRight: Radius.circular(20.0),
  209. bottomRight: Radius.circular(20.0))),
  210. gradient: LinearGradient(
  211. colors: gradient,
  212. begin: Alignment.topLeft,
  213. end: Alignment.bottomRight),
  214. ),
  215. child: Text(title,
  216. style: TextStyle(
  217. color: Colors.white,
  218. fontSize: 15,
  219. fontWeight: FontWeight.w500)),
  220. padding: EdgeInsets.all(10),
  221. ),
  222. Visibility(
  223. visible: isEndIconVisible,
  224. child: Padding(
  225. padding: EdgeInsets.only(right: 10),
  226. child: ImageIcon(
  227. AssetImage("assets/images/ic_forward.png"),
  228. size: 30,
  229. color: Colors.white,
  230. )),
  231. ),
  232. ],
  233. ),
  234. );
  235. });
  236. }
  237. //Alert Dialog
  238. showAlertDialog(BuildContext context) {
  239. // set up the button
  240. Widget okButton = TextButton(
  241. child: Text("OK"),
  242. onPressed: () {
  243. Navigator.of(context, rootNavigator: true).pop();
  244. Navigator.pushAndRemoveUntil(
  245. context,
  246. MaterialPageRoute(
  247. builder: (context) => LoginView()),
  248. (route) => false);
  249. },
  250. );
  251. // set up the AlertDialog
  252. AlertDialog alert = AlertDialog(
  253. title: Text("Employee Self Service"),
  254. content: Text("Please check your email."),
  255. actions: [
  256. okButton,
  257. ],
  258. );
  259. // show the dialog
  260. showDialog(
  261. context: context,
  262. builder: (BuildContext context) {
  263. return alert;
  264. },
  265. );
  266. }
  267. const List<Color> Gradients1 = [
  268. Color(0xFF0EDED2),
  269. Color(0xFF03A0FE),
  270. ];
  271. const List<Color> Gradients2 = [
  272. Color(0xFFFF9945),
  273. Color(0xFFFc6076),
  274. ];