userLogin.dart 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. import 'package:flutter/material.dart';
  2. import '../../../services/auth.dart';
  3. import '../userHome/userCustomizedOrder.dart';
  4. import '../home_page.dart';
  5. class userLogin extends StatefulWidget {
  6. @override
  7. State<userLogin> createState() => _userLoginState();
  8. }
  9. class _userLoginState extends State<userLogin> {
  10. final AuthService _auth = AuthService();
  11. final _formKey = GlobalKey<FormState>();
  12. String error = '';
  13. bool loading = false;
  14. // text field state
  15. String email = '';
  16. String password = '';
  17. @override
  18. Widget build(BuildContext context) {
  19. return Scaffold(
  20. backgroundColor: Colors.white,
  21. appBar: AppBar(
  22. leading:
  23. //back to previous page
  24. IconButton(
  25. icon: const Icon(
  26. Icons.chevron_left,
  27. size: 36,
  28. ),
  29. onPressed: () {
  30. Navigator.push(
  31. context,
  32. MaterialPageRoute(builder: (context) => const HomePage()),
  33. );
  34. },
  35. ),
  36. ),
  37. body:
  38. SingleChildScrollView(
  39. child: Column(
  40. children: <Widget>[
  41. Padding(
  42. padding: const EdgeInsets.all(16.0),
  43. child: Column(
  44. mainAxisAlignment: MainAxisAlignment.start, // Align at the top
  45. crossAxisAlignment: CrossAxisAlignment.center,
  46. children: [
  47. // Title: Login
  48. const Align(
  49. alignment: Alignment.centerLeft,
  50. child: Text(
  51. "Login",
  52. style: TextStyle(
  53. fontFamily: 'Poppins',
  54. fontSize: 30,
  55. fontWeight: FontWeight.bold,
  56. color: Colors.black,
  57. ),
  58. ),
  59. ),
  60. // Input student email
  61. const SizedBox(height: 10),
  62. Container(
  63. width: 334,
  64. height: 52,
  65. decoration: BoxDecoration(
  66. borderRadius: BorderRadius.circular(8),
  67. color: Colors.white,
  68. border: Border.all(
  69. color: const Color.fromRGBO(165, 165, 165, 1),
  70. width: 1,
  71. ),
  72. ),
  73. child: Padding(
  74. padding: const EdgeInsets.symmetric(horizontal: 10.0),
  75. child: TextFormField(
  76. decoration: const InputDecoration(
  77. hintText: "UPM Email",
  78. hintStyle: TextStyle(
  79. fontFamily: 'Poppins',
  80. fontSize: 20,
  81. color: Color.fromRGBO(165, 165, 165, 1),
  82. ),
  83. border: InputBorder.none,
  84. ),
  85. style: const TextStyle(
  86. fontFamily: 'Poppins',
  87. fontSize: 20,
  88. color: Colors.black, // input text color
  89. ),
  90. validator: (val) => val!.isEmpty ? 'Enter a student email' : null,
  91. onChanged: (val) {
  92. setState(() => email = val);
  93. },
  94. ),
  95. ),
  96. ),
  97. // Input Password
  98. const SizedBox(height: 10),
  99. Container(
  100. width: 334,
  101. height: 52,
  102. decoration: BoxDecoration(
  103. borderRadius: BorderRadius.circular(8),
  104. color: Colors.white,
  105. border: Border.all(
  106. color: const Color.fromRGBO(165, 165, 165, 1),
  107. width: 1,
  108. ),
  109. ),
  110. child: Padding(
  111. padding: const EdgeInsets.symmetric(horizontal: 10.0),
  112. child: TextFormField(
  113. decoration: const InputDecoration(
  114. hintText: "Password",
  115. hintStyle: TextStyle(
  116. fontFamily: 'Poppins',
  117. fontSize: 20,
  118. color: Color.fromRGBO(165, 165, 165, 1),
  119. ),
  120. border: InputBorder.none,
  121. ),
  122. style: const TextStyle(
  123. fontFamily: 'Poppins',
  124. fontSize: 20,
  125. color: Colors.black, // input text color
  126. ),
  127. validator: (val) =>
  128. val!.length < 6 ? 'Enter a password 6+ chars long' : null,
  129. obscureText: true,
  130. onChanged: (val) {
  131. setState(() => password = val);
  132. },
  133. ),
  134. ),
  135. ),
  136. // Login
  137. const SizedBox(height: 20),
  138. Container(
  139. width: 334,
  140. height: 65,
  141. decoration: BoxDecoration(
  142. borderRadius: BorderRadius.circular(10),
  143. color: const Color.fromRGBO(119, 97, 255, 1.0),
  144. ),
  145. child: TextButton(
  146. onPressed: () async {
  147. Navigator.push(
  148. context,
  149. MaterialPageRoute(builder: (context) => userCustomizedOrder()),
  150. );
  151. // print(email);
  152. // print(password);
  153. // if (_formKey.currentState!.validate()) {
  154. // setState(() => loading = true);
  155. // dynamic result = await _auth.signInWithEmailAndPassword(email, password);
  156. // if (result == null) {
  157. // setState(() {
  158. // setState(() {
  159. // loading = false;
  160. // error = 'Could not sign in with those credentials';
  161. // });
  162. // });
  163. // }
  164. // }
  165. },
  166. child: const Text(
  167. 'Continue',
  168. style: TextStyle(
  169. fontFamily: 'Poppins',
  170. fontSize: 17,
  171. fontWeight: FontWeight.bold,
  172. color: Colors.white,
  173. ),
  174. ),
  175. ),
  176. ),
  177. // Forget Password little button
  178. const SizedBox(height: 10),
  179. TextButton(
  180. onPressed: () {
  181. // Handle forgot password button press
  182. },
  183. child: const Text(
  184. 'Forgot password',
  185. style: TextStyle(
  186. fontFamily: 'Poppins',
  187. fontSize: 17,
  188. fontWeight: FontWeight.w500,
  189. decoration: TextDecoration.underline,
  190. color: Color.fromRGBO(119, 97, 255, 1.0),
  191. ),
  192. ),
  193. ),
  194. ],
  195. ),
  196. ),
  197. ],
  198. ),
  199. )
  200. );
  201. }
  202. }