userRegister.dart 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367
  1. import 'package:flutter/material.dart';
  2. import '../../../services/auth.dart';
  3. class userRegister extends StatefulWidget {
  4. @override
  5. State<userRegister> createState() => _userRegisterState();
  6. }
  7. class _userRegisterState extends State<userRegister> {
  8. final AuthService _auth = AuthService();
  9. final _formKey = GlobalKey<FormState>();
  10. // text field state
  11. String name = '';
  12. String email = '';
  13. String phoneNumber = '';
  14. String icNumber = '';
  15. String password = '';
  16. String passwordCheck = '';
  17. String error = '';
  18. bool loading = false;
  19. int InputFontsize = 15;
  20. @override
  21. Widget build(BuildContext context) {
  22. return Scaffold(
  23. backgroundColor: Colors.white,
  24. appBar: AppBar(
  25. leading: IconButton(
  26. icon: const Icon(
  27. Icons.chevron_left,
  28. size: 36,
  29. ),
  30. onPressed: () {
  31. Navigator.pop(context);
  32. },
  33. ),
  34. ),
  35. body:
  36. SingleChildScrollView(
  37. child: Form(
  38. key: _formKey,
  39. child: Column(
  40. children: <Widget>[
  41. Padding(
  42. padding: const EdgeInsets.symmetric(vertical: 16.0, horizontal: 50),
  43. child: Column(
  44. mainAxisAlignment: MainAxisAlignment.start, // Align at the top
  45. crossAxisAlignment: CrossAxisAlignment.center,
  46. children: [
  47. const Align(
  48. alignment: Alignment.centerLeft,
  49. child: Text(
  50. "Register",
  51. style: TextStyle(
  52. fontFamily: 'Poppins',
  53. fontSize: 30,
  54. fontWeight: FontWeight.bold,
  55. color: Colors.black,
  56. ),
  57. ),
  58. ),
  59. // Input name
  60. const SizedBox(height: 10),
  61. Container(
  62. width: 334,
  63. height: 52,
  64. decoration: BoxDecoration(
  65. borderRadius: BorderRadius.circular(8),
  66. color: Colors.white,
  67. border: Border.all(
  68. color: const Color.fromRGBO(165, 165, 165, 1),
  69. width: 1,
  70. ),
  71. ),
  72. child: Padding(
  73. padding: const EdgeInsets.symmetric(horizontal: 20.0),
  74. child:
  75. TextFormField(
  76. decoration: const InputDecoration(
  77. hintText: "Name",
  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!.length < 4 ? 'Enter a name more than 3 chars' : null,
  91. onChanged: (val) {
  92. setState(() => name = val);
  93. },
  94. ),
  95. ),
  96. ),
  97. // Input UPM email
  98. const SizedBox(height: 20),
  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: "UPM email",
  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 < 4 ? 'Enter your UPM email' : null,
  129. obscureText: false,
  130. onChanged: (val) {
  131. setState(() => email= val);
  132. },
  133. ),
  134. ),
  135. ),
  136. // Input Phone Number
  137. const SizedBox(height: 20),
  138. Container(
  139. width: 334,
  140. height: 52,
  141. decoration: BoxDecoration(
  142. borderRadius: BorderRadius.circular(8),
  143. color: Colors.white,
  144. border: Border.all(
  145. color: const Color.fromRGBO(165, 165, 165, 1),
  146. width: 1,
  147. ),
  148. ),
  149. child: Padding(
  150. padding: const EdgeInsets.symmetric(horizontal: 10.0),
  151. child: TextFormField(
  152. decoration: const InputDecoration(
  153. hintText: "Phone Number (11-, not 011-)",
  154. hintStyle: TextStyle(
  155. fontFamily: 'Poppins',
  156. // fontSize: 20,
  157. color: Color.fromRGBO(165, 165, 165, 1),
  158. ),
  159. border: InputBorder.none,
  160. ),
  161. style: const TextStyle(
  162. fontFamily: 'Poppins',
  163. // fontSize: 20,
  164. color: Colors.black, // input text color
  165. ),
  166. validator: (val) =>
  167. val!.length != 10 ? 'Enter a valid phone number' : null,
  168. obscureText: false,
  169. onChanged: (val) {
  170. setState(() => phoneNumber = val);
  171. },
  172. ),
  173. ),
  174. ),
  175. // Input IC number
  176. const SizedBox(height: 20),
  177. Container(
  178. width: 334,
  179. height: 52,
  180. decoration: BoxDecoration(
  181. borderRadius: BorderRadius.circular(8),
  182. color: Colors.white,
  183. border: Border.all(
  184. color: const Color.fromRGBO(165, 165, 165, 1),
  185. width: 1,
  186. ),
  187. ),
  188. child: Padding(
  189. padding: const EdgeInsets.symmetric(horizontal: 10.0),
  190. child: TextFormField(
  191. decoration: const InputDecoration(
  192. hintText: "IC Number / Passort Number",
  193. hintStyle: TextStyle(
  194. fontFamily: 'Poppins',
  195. // fontSize: 20,
  196. color: Color.fromRGBO(165, 165, 165, 1),
  197. ),
  198. border: InputBorder.none,
  199. ),
  200. style: const TextStyle(
  201. fontFamily: 'Poppins',
  202. // fontSize: 20,
  203. color: Colors.black, // input text color
  204. ),
  205. validator: (val) =>
  206. val!.length != 12 || val!.length != 9 ? 'Enter a valid IC/Passport Number' : null,
  207. obscureText: false,
  208. onChanged: (val) {
  209. setState(() => icNumber = val);
  210. },
  211. ),
  212. ),
  213. ),
  214. // Input Password
  215. const SizedBox(height: 20),
  216. Container(
  217. width: 334,
  218. height: 52,
  219. decoration: BoxDecoration(
  220. borderRadius: BorderRadius.circular(8),
  221. color: Colors.white,
  222. border: Border.all(
  223. color: const Color.fromRGBO(165, 165, 165, 1),
  224. width: 1,
  225. ),
  226. ),
  227. child: Padding(
  228. padding: const EdgeInsets.symmetric(horizontal: 10.0),
  229. child: TextFormField(
  230. decoration: const InputDecoration(
  231. hintText: "Password",
  232. hintStyle: TextStyle(
  233. fontFamily: 'Poppins',
  234. // fontSize: 20,
  235. color: Color.fromRGBO(165, 165, 165, 1),
  236. ),
  237. border: InputBorder.none,
  238. ),
  239. style: const TextStyle(
  240. fontFamily: 'Poppins',
  241. // fontSize: 20,
  242. color: Colors.black, // input text color
  243. ),
  244. validator: (val) =>
  245. val!.length < 6 ? 'Enter a password > 6 chars long' : null,
  246. obscureText: true,
  247. onChanged: (val) {
  248. setState(() => password = val);
  249. },
  250. ),
  251. ),
  252. ),
  253. // Check Password
  254. const SizedBox(height: 20),
  255. Container(
  256. width: 334,
  257. height: 52,
  258. decoration: BoxDecoration(
  259. borderRadius: BorderRadius.circular(8),
  260. color: Colors.white,
  261. border: Border.all(
  262. color: const Color.fromRGBO(165, 165, 165, 1),
  263. width: 1,
  264. ),
  265. ),
  266. child: Padding(
  267. padding: const EdgeInsets.symmetric(horizontal: 10.0),
  268. child: TextFormField(
  269. decoration: const InputDecoration(
  270. hintText: "Password again",
  271. hintStyle: TextStyle(
  272. fontFamily: 'Poppins',
  273. // fontSize: 20,
  274. color: Color.fromRGBO(165, 165, 165, 1),
  275. ),
  276. border: InputBorder.none,
  277. ),
  278. style: const TextStyle(
  279. fontFamily: 'Poppins',
  280. // fontSize: 20,
  281. color: Colors.black, // input text color
  282. ),
  283. validator: (val) =>
  284. val! != password ? 'Passwords are different' : null,
  285. obscureText: true,
  286. ),
  287. ),
  288. ),
  289. // Register
  290. const SizedBox(height: 30),
  291. Container(
  292. width: 334,
  293. height: 65,
  294. decoration: BoxDecoration(
  295. borderRadius: BorderRadius.circular(10),
  296. color: const Color.fromRGBO(119, 97, 255, 1.0),
  297. ),
  298. child: TextButton(
  299. onPressed: () async {
  300. if (_formKey.currentState!.validate()) {
  301. setState(() => loading = true);
  302. dynamic result = await _auth.registerWithEmailAndPassword(
  303. email, password);
  304. if (result == null) {
  305. setState(() {
  306. loading = false;
  307. error = 'Please supply a valid email';
  308. });
  309. }
  310. }
  311. // // Handle Next button press
  312. // print(email);
  313. // print(password);
  314. // print(phoneNumber);
  315. //
  316. // Navigator.push(
  317. // context,
  318. // MaterialPageRoute(builder: (context) => userRegisterSuccess()),
  319. // );
  320. },
  321. child: const Text(
  322. 'Register',
  323. style: TextStyle(
  324. fontFamily: 'Poppins',
  325. fontSize: 17,
  326. fontWeight: FontWeight.bold,
  327. color: Colors.white,
  328. ),
  329. ),
  330. ),
  331. ),
  332. const SizedBox(height: 20),
  333. ],
  334. ),
  335. ),
  336. Text(
  337. error,
  338. style: const TextStyle(color: Colors.red, fontSize: 14.0),
  339. ),
  340. ],
  341. ),
  342. )
  343. )
  344. );
  345. }
  346. }