SignupPage.dart 9.4 KB

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