Aucune description

profileinfo.dart 6.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. import 'package:flutter_login/flutter_login.dart';
  2. import 'package:flutter/material.dart';
  3. import 'package:google_fonts/google_fonts.dart';
  4. import 'register.dart';
  5. import 'package:http/http.dart' as http;
  6. class ProfilePage extends StatefulWidget{
  7. ProfilePage({Key key, this.title}) : super(key: key);
  8. final String title;
  9. @override
  10. _ProfilePageState createState() => _ProfilePageState();
  11. }
  12. class _ProfilePageState extends State<ProfilePage>{
  13. TextEditingController first_name = new TextEditingController();
  14. TextEditingController last_name = new TextEditingController() ;
  15. TextEditingController country = new TextEditingController();
  16. TextEditingController city = new TextEditingController();
  17. TextEditingController phone = new TextEditingController();
  18. TextEditingController healthcare = new TextEditingController();
  19. // trying to create a an array of controllers
  20. // final List<TextEditingController> controllers = List();
  21. // controllers.add(first_name);
  22. Future<List> clear_controllers() async {
  23. first_name.text = "";
  24. last_name.text = "";
  25. country.text = "";
  26. city.text = "";
  27. phone.text = "";
  28. healthcare.text = "";
  29. }
  30. _Notice(BuildContext context, String message, int r, int g, int b){
  31. showDialog<void>(
  32. context: context,
  33. barrierDismissible: false,
  34. barrierColor: Colors.transparent,
  35. builder: (BuildContext context){
  36. Future.delayed(Duration(seconds: 3), () {
  37. Navigator.of(context).pop(true);
  38. });
  39. return Material(
  40. color: Colors.transparent,
  41. child: InkResponse(
  42. child: Container(
  43. alignment: Alignment.bottomCenter,
  44. padding: EdgeInsets.only(bottom: 130),
  45. child: Text(
  46. message,
  47. style: TextStyle(fontSize: 20, color: Color.fromARGB(255, r, g, b)),),
  48. ),
  49. )
  50. );
  51. }
  52. );
  53. }
  54. Future<List> send_data() async {
  55. var url = 'https://ada.uprrp.edu/~hector.sierra/FastMed/UpdateProfile.php';
  56. final data = await http.post(url, body: {
  57. "first_name": first_name.text,
  58. "last_name": last_name.text,
  59. "country": country.text,
  60. "city": city.text,
  61. "phone": phone.text,
  62. "healthcare": healthcare.text,
  63. });
  64. print(data.body);
  65. if("User not registered" == data.body){
  66. _Notice(context, "Error, unable to update profile", 255, 0, 0);
  67. }
  68. else{
  69. _Notice(context, "Profile Updated", 0, 255, 0);
  70. }
  71. }
  72. Widget _BackButton(BuildContext context) {
  73. return InkWell(
  74. onTap: () {
  75. Navigator.pop(context);
  76. },
  77. child: Row(
  78. children: <Widget>[
  79. Container(
  80. padding: EdgeInsets.only(left: 0, top: 10, bottom: 10),
  81. child: Icon(Icons.arrow_back_ios, color: Colors.black),
  82. ),
  83. Text("Back",
  84. style: TextStyle(fontSize: 14, fontWeight: FontWeight.w500))
  85. ]
  86. ),
  87. );
  88. }
  89. Widget _SubmitButton(BuildContext context) {
  90. return InkResponse(
  91. onTap: () {
  92. send_data();
  93. // clear_controllers();
  94. },
  95. child: Material(
  96. borderRadius: BorderRadius.circular(30),
  97. elevation: 3,
  98. child: Container(
  99. padding: EdgeInsets.symmetric(vertical: 10),
  100. width: 250,
  101. alignment: Alignment.center,
  102. decoration: BoxDecoration(
  103. color: Colors.red,
  104. borderRadius: BorderRadius.circular(30),
  105. ),
  106. child: Text(
  107. "Update",
  108. style: TextStyle(fontSize: 22, color: Colors.white),
  109. ),
  110. ),
  111. ),
  112. );
  113. }
  114. Widget _Fills() {
  115. return Column(
  116. children: <Widget>[
  117. _EntryField("First Name", first_name),
  118. _EntryField("Last Name", last_name),
  119. _EntryField("Country", country),
  120. _EntryField("City", city),
  121. _EntryField("Phone Number", phone),
  122. _EntryField("Healthcare Provider", healthcare),
  123. ]
  124. );
  125. }
  126. Widget _EntryField(String title, TextEditingController controller,
  127. {bool pass = false}) {
  128. return Container(
  129. padding: EdgeInsets.only(left: 0, top: 10, bottom: 10),
  130. child: Column(
  131. crossAxisAlignment: CrossAxisAlignment.start,
  132. children: <Widget>[
  133. Text(
  134. title,
  135. style: TextStyle(fontWeight: FontWeight.bold, fontSize: 18),
  136. ),
  137. SizedBox(
  138. height: 30
  139. ),
  140. TextField(
  141. controller: controller,
  142. obscureText: pass,
  143. decoration: InputDecoration(
  144. border: (
  145. UnderlineInputBorder()
  146. ),
  147. ),
  148. )
  149. ]
  150. ),
  151. );
  152. }
  153. @override
  154. Widget build(BuildContext context) {
  155. final height = MediaQuery.of(context).size.height;
  156. return Scaffold(
  157. body: Container(
  158. height: height,
  159. child: Stack(
  160. children: <Widget>[
  161. Container(
  162. padding: EdgeInsets.symmetric(horizontal: 20),
  163. child: SingleChildScrollView(
  164. child: Column(
  165. crossAxisAlignment: CrossAxisAlignment.center,
  166. mainAxisAlignment: MainAxisAlignment.center,
  167. children: <Widget>[
  168. SizedBox(
  169. height: 60,
  170. ),
  171. _Fills(),
  172. //Add code to verify if password and confirm password match
  173. SizedBox(
  174. height: 80,
  175. ),
  176. _SubmitButton(context),
  177. SizedBox(
  178. height: 50,
  179. ),
  180. // ElevatedButton(
  181. // onPressed: send_data, child: Text("Register")),
  182. ],
  183. ),
  184. )
  185. ),
  186. // Positioned(
  187. // top: 15, left: 20, child: _BackButton(context),
  188. // ),
  189. ],
  190. ),
  191. )
  192. );
  193. }
  194. }