No Description

register.dart 7.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  1. import 'dart:convert';
  2. import 'package:flutter_login/flutter_login.dart';
  3. import 'package:flutter/material.dart';
  4. import 'package:google_fonts/google_fonts.dart';
  5. import 'package:http/http.dart' as http;
  6. import 'dart:convert' as convert;
  7. //
  8. //Still to add:
  9. // Email verification, that the input has "@" and "."
  10. // Hash the passwords
  11. // Allow users to login
  12. // Verify password and confirm password match
  13. //
  14. class RegisterPage extends StatefulWidget{
  15. RegisterPage({Key key, this.title}) : super(key: key);
  16. final String title;
  17. @override
  18. _RegisterPageState createState() => _RegisterPageState();
  19. }
  20. class _RegisterPageState extends State<RegisterPage> {
  21. // TextEditingController name = new TextEditingController();
  22. TextEditingController email = new TextEditingController();
  23. TextEditingController password = new TextEditingController() ;
  24. TextEditingController confirmpass = new TextEditingController();
  25. Future<List> send_data() async {
  26. var url = 'https://ada.uprrp.edu/~hector.sierra/FastMed/API/InsertUser.php';
  27. final data = await http.post(url, body: {
  28. "email": email.text,
  29. "password": password.text,
  30. });
  31. print(data.body);
  32. if("user not registered" == data.body){
  33. print("maybe we use this");
  34. }
  35. }
  36. bool _SamePass() {
  37. if (password.text == confirmpass.text) {
  38. return true;
  39. }
  40. else {
  41. return false;
  42. }
  43. }
  44. _Alerts(BuildContext context){
  45. TextEditingController msg = new TextEditingController();
  46. //
  47. //Useful code for adding pop up messages with animations
  48. //
  49. //
  50. // Navigator.of(context).push(
  51. //
  52. // PageRouteBuilder(
  53. // transitionDuration: Duration(seconds: 2),
  54. // pageBuilder: (context, animation, secAnimation ) => AlertDialog(
  55. // title: Text("Testing"),
  56. // elevation: 1,
  57. // backgroundColor: Colors.transparent,
  58. //
  59. // ),
  60. // opaque: false,
  61. // )
  62. //
  63. // );
  64. showDialog<void>(
  65. context: context,
  66. barrierDismissible: false,
  67. barrierColor: Colors.transparent,
  68. builder: (BuildContext context){
  69. Future.delayed(Duration(seconds: 2), () {
  70. Navigator.of(context).pop(true);
  71. });
  72. return Material(
  73. color: Colors.transparent,
  74. child: InkResponse(
  75. child: Container(
  76. alignment: Alignment.bottomCenter,
  77. padding: EdgeInsets.only(bottom: 30),
  78. child: Text(
  79. "Email address is already registered",
  80. style: TextStyle(fontSize: 18, color: Colors.red),),
  81. ),
  82. )
  83. );
  84. // return Banner(
  85. // location: BannerLocation.bottomEnd,
  86. // message: "Hello there",
  87. //
  88. // );
  89. // // allows the message to disappear
  90. // Future.delayed(Duration(seconds: 2), () {
  91. // Navigator.of(context).pop(true);
  92. // });
  93. // return AlertDialog(
  94. // buttonPadding: ,
  95. // title: Text("Testing"),
  96. // elevation: 1,
  97. // backgroundColor: Colors.transparent,
  98. // );
  99. }
  100. );
  101. }
  102. Widget _BackButton(BuildContext context) {
  103. return InkWell(
  104. onTap: () {
  105. Navigator.pop(context);
  106. },
  107. child: Row(
  108. children: <Widget>[
  109. Container(
  110. padding: EdgeInsets.only(left: 0, top: 10, bottom: 10),
  111. child: Icon(Icons.arrow_back_ios, color: Colors.black),
  112. ),
  113. Text("Back",
  114. style: TextStyle(fontSize: 14, fontWeight: FontWeight.w500))
  115. ]
  116. ),
  117. );
  118. }
  119. Widget _SubmitButton(BuildContext context) {
  120. return InkResponse(
  121. onTap: () {
  122. send_data();
  123. // _Alert(BuildContext);
  124. // _Match(context);
  125. _Alerts(context);
  126. },
  127. child: Material(
  128. borderRadius: BorderRadius.circular(30),
  129. elevation: 3,
  130. child: Container(
  131. padding: EdgeInsets.symmetric(vertical: 10),
  132. width: 250,
  133. alignment: Alignment.center,
  134. decoration: BoxDecoration(
  135. color: Colors.red,
  136. borderRadius: BorderRadius.circular(30),
  137. ),
  138. child: Text(
  139. "Submit",
  140. style: TextStyle(fontSize: 22, color: Colors.white),
  141. ),
  142. ),
  143. ),
  144. );
  145. }
  146. Widget _EntryField(String title, TextEditingController controller,
  147. {bool pass = false}) {
  148. return Container(
  149. padding: EdgeInsets.only(left: 0, top: 10, bottom: 10),
  150. child: Column(
  151. crossAxisAlignment: CrossAxisAlignment.start,
  152. children: <Widget>[
  153. Text(
  154. title,
  155. style: TextStyle(fontWeight: FontWeight.bold, fontSize: 18),
  156. ),
  157. SizedBox(
  158. height: 30
  159. ),
  160. TextField(
  161. controller: controller,
  162. obscureText: pass,
  163. decoration: InputDecoration(
  164. border: (
  165. UnderlineInputBorder()
  166. ),
  167. ),
  168. )
  169. ]
  170. ),
  171. );
  172. }
  173. Widget _Fills() {
  174. return Column(
  175. children: <Widget>[
  176. _EntryField("Email", email),
  177. _EntryField("Password", password, pass: true),
  178. _EntryField("Confirm Password", confirmpass, pass: true)
  179. ]
  180. );
  181. }
  182. //add column or stack
  183. @override
  184. Widget build(BuildContext context) {
  185. final height = MediaQuery
  186. .of(context)
  187. .size
  188. .height;
  189. return Scaffold(
  190. body: Container(
  191. height: height,
  192. child: Stack(
  193. children: <Widget>[
  194. Container(
  195. padding: EdgeInsets.symmetric(horizontal: 20),
  196. child: SingleChildScrollView(
  197. child: Column(
  198. crossAxisAlignment: CrossAxisAlignment.center,
  199. mainAxisAlignment: MainAxisAlignment.center,
  200. children: <Widget>[
  201. // Text("Username", style: TextStyle(fontSize: 18.0),),
  202. // TextField(
  203. // controller: name,
  204. // decoration: InputDecoration(
  205. // hintText: 'name'
  206. // ),
  207. // ),
  208. SizedBox(
  209. height: 700,
  210. ),
  211. _Fills(),
  212. //Add code to verify if password and confirm password match
  213. SizedBox(
  214. height: 20,
  215. ),
  216. _SubmitButton(context),
  217. SizedBox(
  218. height: 10,
  219. ),
  220. // ElevatedButton(
  221. // onPressed: send_data, child: Text("Register")),
  222. ],
  223. ),
  224. )
  225. ),
  226. Positioned(
  227. top: 15, left: 20, child: _BackButton(context),
  228. ),
  229. ],
  230. ),
  231. )
  232. );
  233. }
  234. }