Ei kuvausta
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 12KB

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