SignupPage.dart 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329
  1. import 'package:flutter/material.dart';
  2. import 'package:physigo/Services/AuthServiec.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. child: Icon(Icons.navigate_before_outlined),
  54. onPressed: () => _updatePageIndex(_pageIndex - 1)),
  55. SizedBox(
  56. width: 25,
  57. ),
  58. FloatingActionButton(
  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. TextFormField(
  183. controller: _address,
  184. decoration: InputDecoration(
  185. hintText: 'Home Adress..',
  186. ),
  187. ),
  188. const SizedBox(height: 10),
  189. Row(children: <Widget>[
  190. Text('Anonymous'),
  191. Checkbox(
  192. checkColor: Colors.white,
  193. value: anonymous,
  194. onChanged: (bool? value) {
  195. setState(() {
  196. anonymous = value!;
  197. });
  198. },
  199. ),
  200. ]),
  201. const SizedBox(height: 10),
  202. ]),
  203. )),
  204. );
  205. }
  206. }
  207. class SignupForm3 extends StatefulWidget {
  208. const SignupForm3({Key? key, required this.title}) : super(key: key);
  209. final String title;
  210. @override
  211. //_RegisterScreen createState() => _RegisterScreen();
  212. State<SignupForm3> createState() => _SignupForm3();
  213. }
  214. class _SignupForm3 extends State<SignupForm3> {
  215. @override
  216. Widget build(BuildContext context) {
  217. return Scaffold(
  218. appBar: AppBar(
  219. title: const Text('Register Screen'),
  220. ),
  221. body: Center(
  222. child: SizedBox(
  223. width: 300,
  224. child: Column(children: <Widget>[
  225. const SizedBox(height: 30),
  226. Text(
  227. 'User details',
  228. style: TextStyle(fontSize: 25, fontWeight: FontWeight.bold),
  229. ),
  230. const SizedBox(height: 30),
  231. Image.asset(
  232. 'assets/id-card.png',
  233. width: 150,
  234. ),
  235. const SizedBox(height: 30),
  236. TextFormField(
  237. controller: _username,
  238. decoration: InputDecoration(
  239. hintText: 'Username',
  240. ),
  241. ),
  242. const SizedBox(height: 10),
  243. TextFormField(
  244. controller: _passwd,
  245. decoration: InputDecoration(
  246. hintText: 'Password',
  247. ),
  248. ),
  249. const SizedBox(height: 10),
  250. TextFormField(
  251. controller: _passwd2,
  252. decoration: InputDecoration(
  253. hintText: 'Repeat password',
  254. ),
  255. ),
  256. const SizedBox(height: 15),
  257. ElevatedButton(
  258. onPressed: () {
  259. try {
  260. if (_passwd.text == _passwd2.text) {
  261. createUser();
  262. Navigator.pop(context);
  263. } else {
  264. print("passwd is not the same");
  265. }
  266. } catch (e) {
  267. print(e.toString());
  268. }
  269. },
  270. child: const Text('Finish Register'))
  271. ]),
  272. )),
  273. );
  274. }
  275. void createUser() async {
  276. dynamic result =
  277. await _auth.createNewUser(_name.text, _mail.text, _passwd.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('***** address: ' + _address.text +
  284. ' anonymous: ' + anonymous.toString() +
  285. ' birthdate: ' + _dateString.toString() +
  286. ' createDate: ' + DateTime.now().toString()+
  287. ' last_challenge_data: ' + 'null'+
  288. ' mail: ' + _mail.text +
  289. ' name: ' + _name.text +
  290. ' passwd: ' + '??? ' +
  291. ' phone_number: ' + _phoneNumber.text+
  292. ' shared_id: ' + _username.text +
  293. ' surname: ' + _surname.text +
  294. ' totalpoints: 0 ' +
  295. ' update_date: ' + DateTime.now().toString()+
  296. ' weeklyplace: ' + 'null');
  297. _name.clear();
  298. _surname.clear();
  299. _mail.clear();
  300. _phoneNumber.clear();
  301. _address.clear();
  302. _username.clear();
  303. _passwd.clear();
  304. _passwd2.clear();
  305. }
  306. }
  307. }