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

login_screen.dart 10KB

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