SignupPage.dart 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340
  1. import 'package:flutter/material.dart';
  2. import 'package:physigo/Services/AuthService.dart';
  3. //Fields..
  4. TextEditingController _name = TextEditingController();
  5. TextEditingController _surname = TextEditingController();
  6. TextEditingController _mail = TextEditingController();
  7. TextEditingController _phoneNumber = TextEditingController();
  8. TextEditingController _address = TextEditingController();
  9. TextEditingController _username = TextEditingController();
  10. TextEditingController _passwd = TextEditingController();
  11. TextEditingController _passwd2 = TextEditingController();
  12. bool anonymous = false;
  13. String? _dateString;
  14. class SignupPage extends StatefulWidget {
  15. const SignupPage({Key? key}) : super(key: key);
  16. @override
  17. State<SignupPage> createState() => _SignupPageState();
  18. }
  19. class _SignupPageState extends State<SignupPage> {
  20. int _pageIndex = 0;
  21. List<Widget> forms = [
  22. SignupForm1(
  23. title: '',
  24. ),
  25. SignupForm2(
  26. title: '',
  27. ),
  28. SignupForm3(
  29. title: '',
  30. )
  31. ];
  32. void _updatePageIndex(int newPageIndex) {
  33. if (newPageIndex == -1) {
  34. Navigator.pushNamed(context, '/');
  35. } else if (newPageIndex == 3) {
  36. //autentification
  37. //Navigator.pop(context);
  38. newPageIndex == 2;
  39. } else {
  40. setState(() {
  41. _pageIndex = newPageIndex;
  42. });
  43. }
  44. }
  45. @override
  46. Widget build(BuildContext context) {
  47. return Scaffold(
  48. floatingActionButton: Row(
  49. mainAxisAlignment: MainAxisAlignment.end,
  50. children: [
  51. FloatingActionButton(
  52. heroTag: "btn1",
  53. child: Icon(Icons.navigate_before_outlined),
  54. onPressed: () => _updatePageIndex(_pageIndex - 1)),
  55. SizedBox(
  56. width: 25,
  57. ),
  58. FloatingActionButton(
  59. heroTag: "btn2",
  60. child: Icon(Icons.navigate_next_outlined),
  61. onPressed: () => _updatePageIndex(_pageIndex + 1))
  62. ],
  63. ),
  64. body: Center(child: forms[_pageIndex]),
  65. );
  66. }
  67. }
  68. class SignupForm1 extends StatefulWidget {
  69. const SignupForm1({Key? key, required this.title}) : super(key: key);
  70. final String title;
  71. @override
  72. //_RegisterScreen createState() => _RegisterScreen();
  73. State<SignupForm1> createState() => _SignupForm1();
  74. }
  75. class _SignupForm1 extends State<SignupForm1> {
  76. DateTime? _dateTime;
  77. @override
  78. Widget build(BuildContext context) {
  79. return Scaffold(
  80. appBar: AppBar(
  81. title: const Text('Register Screen'),
  82. ),
  83. body: Center(
  84. child: SizedBox(
  85. width: 300,
  86. child: Column(children: <Widget>[
  87. const SizedBox(height: 30),
  88. Text(
  89. 'Personal Information',
  90. style: TextStyle(fontSize: 25, fontWeight: FontWeight.bold),
  91. ),
  92. const SizedBox(height: 30),
  93. Image.asset(
  94. 'assets/user.png',
  95. width: 150,
  96. ),
  97. const SizedBox(height: 30),
  98. TextFormField(
  99. controller: _name,
  100. decoration: InputDecoration(
  101. hintText: 'Name',
  102. ),
  103. ),
  104. const SizedBox(height: 10),
  105. TextFormField(
  106. controller: _surname,
  107. decoration: InputDecoration(
  108. hintText: 'Surname',
  109. ),
  110. ),
  111. const SizedBox(height: 10),
  112. Row(children: <Widget>[
  113. Text(_dateString == null
  114. ? 'Select birthday date :'
  115. : _dateString.toString()),
  116. const SizedBox(width: 49),
  117. ElevatedButton(
  118. onPressed: () {
  119. showDatePicker(
  120. context: context,
  121. initialDate: DateTime.now(),
  122. firstDate: DateTime(1900),
  123. lastDate: DateTime.now())
  124. .then((date) {
  125. setState(() {
  126. _dateTime = date!;
  127. _dateString = "${date.day}-${date.month}-${date.year}";
  128. });
  129. });
  130. },
  131. child: const Text('Select date'),
  132. ),
  133. ]),
  134. const SizedBox(height: 10),
  135. ]),
  136. )),
  137. );
  138. }
  139. }
  140. class SignupForm2 extends StatefulWidget {
  141. const SignupForm2({Key? key, required this.title}) : super(key: key);
  142. final String title;
  143. @override
  144. //_RegisterScreen createState() => _RegisterScreen();
  145. State<SignupForm2> createState() => _SignupForm2();
  146. }
  147. class _SignupForm2 extends State<SignupForm2> {
  148. @override
  149. Widget build(BuildContext context) {
  150. return Scaffold(
  151. appBar: AppBar(
  152. title: const Text('Register Screen'),
  153. ),
  154. body: Center(
  155. child: SizedBox(
  156. width: 300,
  157. child: Column(children: <Widget>[
  158. const SizedBox(height: 30),
  159. Text(
  160. 'Contact Details',
  161. style: TextStyle(fontSize: 25, fontWeight: FontWeight.bold),
  162. ),
  163. const SizedBox(height: 30),
  164. Image.asset(
  165. 'assets/communicate.png',
  166. width: 150,
  167. ),
  168. const SizedBox(height: 30),
  169. TextFormField(
  170. controller: _mail,
  171. decoration: InputDecoration(
  172. hintText: 'Mail',
  173. ),
  174. ),
  175. const SizedBox(height: 10),
  176. TextFormField(
  177. controller: _phoneNumber,
  178. decoration: InputDecoration(
  179. hintText: 'Phone Number',
  180. ),
  181. ),
  182. const SizedBox(height: 10),
  183. TextFormField(
  184. controller: _address,
  185. decoration: InputDecoration(
  186. hintText: 'Home Adress..',
  187. ),
  188. ),
  189. const SizedBox(height: 10),
  190. Row(children: <Widget>[
  191. Text('Anonymous'),
  192. Checkbox(
  193. checkColor: Colors.white,
  194. value: anonymous,
  195. onChanged: (bool? value) {
  196. setState(() {
  197. anonymous = value!;
  198. });
  199. },
  200. ),
  201. ]),
  202. const SizedBox(height: 10),
  203. ]),
  204. )),
  205. );
  206. }
  207. }
  208. class SignupForm3 extends StatefulWidget {
  209. const SignupForm3({Key? key, required this.title}) : super(key: key);
  210. final String title;
  211. @override
  212. //_RegisterScreen createState() => _RegisterScreen();
  213. State<SignupForm3> createState() => _SignupForm3();
  214. }
  215. class _SignupForm3 extends State<SignupForm3> {
  216. @override
  217. Widget build(BuildContext context) {
  218. return Scaffold(
  219. appBar: AppBar(
  220. title: const Text('Register Screen'),
  221. ),
  222. body: Center(
  223. child: SizedBox(
  224. width: 300,
  225. child: Column(children: <Widget>[
  226. const SizedBox(height: 30),
  227. Text(
  228. 'User details',
  229. style: TextStyle(fontSize: 25, fontWeight: FontWeight.bold),
  230. ),
  231. const SizedBox(height: 30),
  232. Image.asset(
  233. 'assets/id-card.png',
  234. width: 150,
  235. ),
  236. const SizedBox(height: 30),
  237. TextFormField(
  238. controller: _username,
  239. decoration: InputDecoration(
  240. hintText: 'Username',
  241. ),
  242. ),
  243. const SizedBox(height: 10),
  244. TextFormField(
  245. controller: _passwd,
  246. obscureText: true,
  247. enableSuggestions: false,
  248. autocorrect: false,
  249. decoration: InputDecoration(
  250. hintText: 'Password',
  251. ),
  252. ),
  253. const SizedBox(height: 10),
  254. TextFormField(
  255. controller: _passwd2,
  256. obscureText: true,
  257. enableSuggestions: false,
  258. autocorrect: false,
  259. decoration: InputDecoration(
  260. hintText: 'Repeat password',
  261. ),
  262. ),
  263. const SizedBox(height: 15),
  264. ElevatedButton(
  265. onPressed: () {
  266. try {
  267. if (_passwd.text == _passwd2.text) {
  268. createUser();
  269. Navigator.pop(context);
  270. } else {
  271. print("passwd is not the same");
  272. }
  273. } catch (e) {
  274. print(e.toString());
  275. }
  276. },
  277. child: const Text('Finish Register')),
  278. ]),
  279. )),
  280. );
  281. }
  282. void createUser() async {
  283. dynamic result =
  284. await AuthenticationServices.createNewUser(_address.text, anonymous, _dateString.toString(), _name.text, _mail.text, _passwd.text,
  285. _phoneNumber.text, _username.text, _surname.text);
  286. if (result == null) {
  287. print('mail not valid');
  288. } else {
  289. //print(result.toString());
  290. //[51.787378° N, 19.449455° E]
  291. print('***** address: ' + _address.text +
  292. ' anonymous: ' + anonymous.toString() +
  293. ' birthdate: ' + _dateString.toString() +
  294. ' createDate: ' + DateTime.now().toString()+
  295. ' last_challenge_data: ' + 'null'+
  296. ' mail: ' + _mail.text +
  297. ' name: ' + _name.text +
  298. ' passwd: ' + '??? ' +
  299. ' phone_number: ' + _phoneNumber.text+
  300. ' shared_id: ' + _username.text +
  301. ' surname: ' + _surname.text +
  302. ' totalpoints: 0 ' +
  303. ' update_date: ' + DateTime.now().toString()+
  304. ' weeklyplace: ' + 'null');
  305. _name.clear();
  306. _surname.clear();
  307. _mail.clear();
  308. _phoneNumber.clear();
  309. _address.clear();
  310. _username.clear();
  311. _passwd.clear();
  312. _passwd2.clear();
  313. }
  314. }
  315. }