Nav apraksta
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

login_screen.dart 12KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341
  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:tower_app/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. Container(
  77. margin: EdgeInsets.only (top: 15),
  78. padding: EdgeInsets.only(top: 0),
  79. child: Text(
  80. "Login",
  81. style: GoogleFonts.knewave(
  82. color: Colors.blueAccent, fontSize: 25),
  83. ),
  84. ),
  85. ],
  86. ),
  87. Column(
  88. crossAxisAlignment: CrossAxisAlignment.start,
  89. children: <Widget>[
  90. Padding(
  91. padding: EdgeInsets.only(left: 40, bottom: 5, top: 20),
  92. child: Text(
  93. "Username",
  94. style: TextStyle(fontSize: 16, color: Colors.black87, fontWeight: FontWeight.bold),
  95. ),
  96. ),
  97. Stack(
  98. alignment: Alignment.bottomRight,
  99. children: <Widget>[
  100. InputWidgetEmail(20.0, 20.0),
  101. Padding(padding: EdgeInsets.only(right: 50),
  102. ),
  103. ],
  104. ),
  105. ],
  106. ),
  107. Column(
  108. crossAxisAlignment: CrossAxisAlignment.start,
  109. children: <Widget>[
  110. Padding(
  111. padding: EdgeInsets.only(left: 40, bottom: 5),
  112. child: Text(
  113. "Password",
  114. style: TextStyle(fontSize: 16, color: Colors.black87, fontWeight: FontWeight.bold),
  115. ),
  116. ),
  117. Stack(
  118. alignment: Alignment.bottomRight,
  119. children: <Widget>[
  120. InputWidgetPassword(20.0, 20.0),
  121. Padding(
  122. padding: EdgeInsets.only(right: 15),
  123. child: Row(
  124. children: <Widget>[
  125. Expanded(
  126. child: Padding(
  127. padding: EdgeInsets.only(top: 0),
  128. )),
  129. InkWell(
  130. child: Container(
  131. padding: EdgeInsets.all(10),
  132. decoration: ShapeDecoration(
  133. shape: CircleBorder(),
  134. gradient: LinearGradient(
  135. colors: Gradients2,
  136. begin: Alignment.topLeft,
  137. end: Alignment.bottomRight),
  138. ),
  139. child: ImageIcon(
  140. AssetImage("assets/images/ic_forward.png"),
  141. size: 40,
  142. color: Colors.white,
  143. ),
  144. ),
  145. onTap: () async {
  146. if (!validateForm(context)) {
  147. return;
  148. } else {
  149. //Navigator.pushReplacement(context, MaterialPageRoute(builder: (context) => HomeView()));
  150. if (emailController.text.toString() == "user1"){
  151. var prefs = await SharedPreferences.getInstance();
  152. await prefs.setInt('user_id', 2);
  153. emailController.clear();
  154. passwordController.clear();
  155. Navigator.pushReplacement(context, MaterialPageRoute(builder: (context) => HomeView()));
  156. } else if (emailController.text.toString() == "user2"){
  157. var prefs = await SharedPreferences.getInstance();
  158. await prefs.setInt('user_id', 6);
  159. emailController.clear();
  160. passwordController.clear();
  161. Navigator.pushReplacement(context, MaterialPageRoute(builder: (context) => HomeView()));
  162. } else {
  163. Fluttertoast.showToast(
  164. msg: "Wrong Username or Password!",
  165. toastLength: Toast.LENGTH_SHORT,
  166. gravity: ToastGravity.CENTER,
  167. timeInSecForIosWeb: 1,
  168. textColor: Colors.white,
  169. fontSize: 16.0);
  170. }
  171. }
  172. },
  173. )
  174. ],
  175. ),
  176. ),
  177. /*Padding(
  178. padding: EdgeInsets.only(bottom: MediaQuery.of(context).viewInsets.bottom)
  179. )*/
  180. ],
  181. ),
  182. ],
  183. ),
  184. Padding(
  185. padding: EdgeInsets.only(bottom: 10),
  186. ),
  187. /*InkWell(
  188. child:
  189. roundedRectButton("Forgot Password?", Gradients1, false),
  190. onTap: () async {
  191. Navigator.push(
  192. context,
  193. MaterialPageRoute(
  194. builder: (context) => ForgotPasswordView()));
  195. })*/
  196. ],
  197. )
  198. ],
  199. ),
  200. );
  201. }
  202. }
  203. Widget roundedRectButton(String title, List<Color> gradient, bool isEndIconVisible) {
  204. return Builder(builder: (BuildContext mContext) {
  205. return Align(
  206. alignment: Alignment.centerLeft,
  207. child: Stack(
  208. children: <Widget>[
  209. Container(
  210. alignment: Alignment.centerRight,
  211. width: MediaQuery.of(mContext).size.width / 2.45,
  212. decoration: ShapeDecoration(
  213. shape: RoundedRectangleBorder(
  214. borderRadius: BorderRadius.only(
  215. topRight: Radius.circular(20.0),
  216. bottomRight: Radius.circular(20.0))),
  217. gradient: LinearGradient(
  218. colors: gradient,
  219. begin: Alignment.topLeft,
  220. end: Alignment.bottomRight),
  221. ),
  222. child: Text(title,
  223. style: TextStyle(
  224. decoration: TextDecoration.underline,
  225. color: Colors.white,
  226. fontSize: 15,
  227. fontWeight: FontWeight.w500)),
  228. padding: EdgeInsets.all(10),
  229. ),
  230. Visibility(
  231. visible: isEndIconVisible,
  232. child: Padding(
  233. padding: EdgeInsets.only(right: 10),
  234. child: ImageIcon(
  235. AssetImage("assets/images/ic_forward.png"),
  236. size: 30,
  237. color: Colors.white,
  238. )),
  239. ),
  240. ],
  241. ),
  242. );
  243. });
  244. }
  245. const List<Color> Gradients1 = [
  246. /*Color(0xFFFFFFFF),
  247. Color(0xFFFFFFFF),*/
  248. Color(0xFF03A0FE),
  249. Colors.pink,
  250. ];
  251. const List<Color> Gradients2 = [
  252. Color(0xFFFF9945),
  253. Color(0xFFFc6076),
  254. ];
  255. bool validateForm(BuildContext context) {
  256. bool result = true;
  257. if (emailController.text.toString().isEmpty) {
  258. /*final snackBar = SnackBar(content: Text("Email Required"));
  259. ScaffoldMessenger.of(context).showSnackBar(snackBar);*/
  260. Fluttertoast.showToast(
  261. msg: "Username 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. } /*else if (!emailController.text.toString().contains("@")) {
  269. Fluttertoast.showToast(
  270. msg: "Incorrect email format",
  271. toastLength: Toast.LENGTH_SHORT,
  272. gravity: ToastGravity.CENTER,
  273. timeInSecForIosWeb: 1,
  274. textColor: Colors.white,
  275. fontSize: 16.0);
  276. result = false;
  277. }*/ else if (passwordController.text.toString().isEmpty) {
  278. Fluttertoast.showToast(
  279. msg: "Password Required",
  280. toastLength: Toast.LENGTH_SHORT,
  281. gravity: ToastGravity.CENTER,
  282. timeInSecForIosWeb: 1,
  283. textColor: Colors.white,
  284. fontSize: 16.0);
  285. result = false;
  286. }
  287. return result;
  288. }
  289. alertDialogFailedResponse(BuildContext context){
  290. Widget okButton = TextButton(
  291. child: Text("Refresh"),
  292. onPressed: () {
  293. Navigator.of(context, rootNavigator: true).pop();
  294. Navigator.pushReplacement(context, MaterialPageRoute(
  295. builder: (context) => LoginScreen()));
  296. },
  297. );
  298. Widget noButton = TextButton(
  299. child: Text("Back"),
  300. onPressed: () {
  301. Navigator.of(context, rootNavigator: true).pop();
  302. Navigator.pop(context);
  303. },
  304. );
  305. // set up the AlertDialog
  306. AlertDialog alert = AlertDialog(
  307. title: Text("Employee Self Service"),
  308. content: Text("Server Response Error"),
  309. actions: [
  310. noButton,
  311. okButton,
  312. ],
  313. );
  314. // show the dialog
  315. showDialog(
  316. context: context,
  317. barrierDismissible: false,
  318. builder: (BuildContext context) {
  319. return alert;
  320. },
  321. );
  322. }