Ei kuvausta

welcome.dart 5.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. import 'dart:convert';
  2. // import 'dart:html';
  3. import 'dart:io';
  4. import 'package:flutter/cupertino.dart';
  5. import 'package:flutter_login/flutter_login.dart';
  6. import 'package:flutter/material.dart';
  7. import 'package:google_fonts/google_fonts.dart';
  8. import 'register.dart';
  9. import 'package:http/http.dart' as http;
  10. import 'dart:convert' as convert;
  11. import 'navigation.dart';
  12. class WelcomePage extends StatefulWidget {
  13. WelcomePage({Key key, this.title}) : super(key: key);
  14. final String title;
  15. @override
  16. _WelcomePageState createState() => _WelcomePageState();
  17. }
  18. class _WelcomePageState extends State<WelcomePage> {
  19. var Token;
  20. TextEditingController email = new TextEditingController();
  21. TextEditingController password = new TextEditingController();
  22. Future<List> send_data() async {
  23. var url = 'https://ada.uprrp.edu/~hector.sierra/FastMed/API/login.php';
  24. http.Response response = await http.post(url, body: {
  25. "email": email.text,
  26. "password": password.text,
  27. });
  28. print(response.body);
  29. print(response.statusCode);
  30. print(HttpStatus.ok);
  31. if("user not found" == response.body){
  32. print("maybe we use this");
  33. }
  34. else{
  35. print("User found");
  36. Token = email.text;
  37. Navigator.push(
  38. context, MaterialPageRoute(builder: (context) => NavigationPage()));
  39. }
  40. }
  41. Widget _message(BuildContext context){
  42. return RichText(
  43. textAlign: TextAlign.center,
  44. text: TextSpan(
  45. text: "Don't have an account?",
  46. style: GoogleFonts.cabin(
  47. fontSize: 18,
  48. color: Colors.black
  49. )
  50. ),
  51. );
  52. }
  53. Widget _title(BuildContext context){
  54. return RichText(
  55. textAlign: TextAlign.center,
  56. text: TextSpan(
  57. text: "Welcome to FastMed",
  58. style: GoogleFonts.cabin(
  59. fontSize: 30,
  60. color: Colors.red
  61. )
  62. ),
  63. );
  64. }
  65. Widget _LoginField(String title, TextEditingController controller, {bool pass = false}){
  66. return Container(
  67. padding: EdgeInsets.only(left: 0, top: 10, bottom: 10),
  68. child: Column(
  69. crossAxisAlignment: CrossAxisAlignment.start,
  70. children: <Widget> [
  71. Text(
  72. title,
  73. style: TextStyle(fontWeight: FontWeight.bold, fontSize: 18),
  74. ),
  75. SizedBox(
  76. height: 30
  77. ),
  78. TextField(
  79. controller: controller,
  80. obscureText: pass,
  81. decoration: InputDecoration(
  82. border: (
  83. UnderlineInputBorder(
  84. )
  85. ),
  86. ),
  87. ),
  88. ]
  89. ),
  90. );
  91. }
  92. Widget _Fills(){
  93. return Column(
  94. children: <Widget> [
  95. _LoginField("Email", email),
  96. _LoginField("Password", password, pass: true),
  97. ]
  98. );
  99. }
  100. Widget _SubmitButton(BuildContext context){
  101. return InkResponse(
  102. onTap: (){
  103. send_data();
  104. },
  105. child: Container(
  106. padding: EdgeInsets.symmetric(vertical: 10),
  107. width: 180,
  108. alignment: Alignment.center,
  109. decoration: BoxDecoration(
  110. color: Colors.red,
  111. borderRadius: BorderRadius.circular(30),
  112. ),
  113. child: Text(
  114. "Login",
  115. style: TextStyle(fontSize: 22, color: Colors.white),
  116. ),
  117. ),
  118. );
  119. }
  120. Widget _RegisterButton(BuildContext context){
  121. return InkWell(
  122. onTap: () {
  123. Navigator.push(
  124. context, MaterialPageRoute(builder: (context) => RegisterPage()));
  125. },
  126. child: Container(
  127. // width: MediaQuery.of(context).size.width,
  128. width: 180,
  129. padding: EdgeInsets.symmetric(vertical:8),
  130. alignment: Alignment.center,
  131. decoration: BoxDecoration(
  132. color: Colors.red,
  133. // shape:
  134. borderRadius: BorderRadius.circular(30),
  135. ),
  136. child: Text(
  137. "Register",
  138. style: TextStyle(fontSize: 22, color: Colors.white),
  139. ),
  140. )
  141. );
  142. }
  143. @override
  144. Widget build(BuildContext context) {
  145. final height = MediaQuery.of(context).size.height;
  146. return Scaffold(
  147. body: Container(
  148. height: height,
  149. child:Container(
  150. width: MediaQuery.of(context).size.width,
  151. padding: EdgeInsets.symmetric(horizontal: 20),
  152. // height: MediaQuery.of(context).size.height,
  153. decoration: BoxDecoration(
  154. borderRadius: BorderRadius.all(Radius.circular(4)),
  155. boxShadow: [
  156. BoxShadow(
  157. color: Colors.white,
  158. offset: Offset(0,3),
  159. blurRadius: 5,
  160. spreadRadius: 2)
  161. ]
  162. ),
  163. child: SingleChildScrollView(
  164. child: Column(
  165. crossAxisAlignment: CrossAxisAlignment.center,
  166. mainAxisAlignment: MainAxisAlignment.center,
  167. children: <Widget> [
  168. SizedBox(
  169. height: 80,
  170. ),
  171. _title(context),
  172. SizedBox(
  173. height: 150,
  174. ),
  175. // _LogInButton(context),
  176. _Fills(),
  177. SizedBox(
  178. height: 60,
  179. ),
  180. _SubmitButton(context),
  181. SizedBox(
  182. height: 45,
  183. ),
  184. _message(context),
  185. SizedBox(
  186. height: 15,
  187. ),
  188. _RegisterButton(context),
  189. SizedBox(
  190. height: 20,
  191. )
  192. ],
  193. )
  194. ),
  195. ),
  196. )
  197. );
  198. }
  199. }