SignupPage.dart 9.0 KB

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