SignupPage.dart 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334
  1. import 'package:flutter/material.dart';
  2. import 'package:physigo/Services/AuthServiec.dart';
  3. import 'Services/DatabaseManager.dart';
  4. //Fields..
  5. TextEditingController _name = TextEditingController();
  6. TextEditingController _surname = TextEditingController();
  7. TextEditingController _mail = TextEditingController();
  8. TextEditingController _phoneNumber = TextEditingController();
  9. TextEditingController _address = TextEditingController();
  10. TextEditingController _username = TextEditingController();
  11. TextEditingController _passwd = TextEditingController();
  12. TextEditingController _passwd2 = TextEditingController();
  13. bool anonymous = false;
  14. String? _dateString;
  15. final AuthenticationServices _auth = AuthenticationServices();
  16. class SignupPage extends StatefulWidget {
  17. const SignupPage({Key? key}) : super(key: key);
  18. @override
  19. State<SignupPage> createState() => _SignupPageState();
  20. }
  21. class _SignupPageState extends State<SignupPage> {
  22. int _pageIndex = 0;
  23. List<Widget> forms = [
  24. SignupForm1(
  25. title: '',
  26. ),
  27. SignupForm2(
  28. title: '',
  29. ),
  30. SignupForm3(
  31. title: '',
  32. )
  33. ];
  34. void _updatePageIndex(int newPageIndex) {
  35. if (newPageIndex == -1) {
  36. Navigator.pushNamed(context, '/');
  37. } else if (newPageIndex == 3) {
  38. //autentification
  39. //Navigator.pop(context);
  40. newPageIndex == 2;
  41. } else {
  42. setState(() {
  43. _pageIndex = newPageIndex;
  44. });
  45. }
  46. }
  47. @override
  48. Widget build(BuildContext context) {
  49. return Scaffold(
  50. floatingActionButton: Row(
  51. mainAxisAlignment: MainAxisAlignment.end,
  52. children: [
  53. FloatingActionButton(
  54. child: Icon(Icons.navigate_before_outlined),
  55. onPressed: () => _updatePageIndex(_pageIndex - 1)),
  56. SizedBox(
  57. width: 25,
  58. ),
  59. FloatingActionButton(
  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. decoration: InputDecoration(
  247. hintText: 'Password',
  248. ),
  249. ),
  250. const SizedBox(height: 10),
  251. TextFormField(
  252. controller: _passwd2,
  253. decoration: InputDecoration(
  254. hintText: 'Repeat password',
  255. ),
  256. ),
  257. const SizedBox(height: 15),
  258. ElevatedButton(
  259. onPressed: () {
  260. try {
  261. if (_passwd.text == _passwd2.text) {
  262. createUser();
  263. Navigator.pop(context);
  264. } else {
  265. print("passwd is not the same");
  266. }
  267. } catch (e) {
  268. print(e.toString());
  269. }
  270. },
  271. child: const Text('Finish Register')),
  272. ]),
  273. )),
  274. );
  275. }
  276. void createUser() async {
  277. dynamic result =
  278. await _auth.createNewUser(_address.text, anonymous, _dateString.toString(), _name.text, _mail.text, _passwd.text,
  279. _phoneNumber.text, _username.text, _surname.text);
  280. if (result == null) {
  281. print('mail not valid');
  282. } else {
  283. //print(result.toString());
  284. //[51.787378° N, 19.449455° E]
  285. print('***** address: ' + _address.text +
  286. ' anonymous: ' + anonymous.toString() +
  287. ' birthdate: ' + _dateString.toString() +
  288. ' createDate: ' + DateTime.now().toString()+
  289. ' last_challenge_data: ' + 'null'+
  290. ' mail: ' + _mail.text +
  291. ' name: ' + _name.text +
  292. ' passwd: ' + '??? ' +
  293. ' phone_number: ' + _phoneNumber.text+
  294. ' shared_id: ' + _username.text +
  295. ' surname: ' + _surname.text +
  296. ' totalpoints: 0 ' +
  297. ' update_date: ' + DateTime.now().toString()+
  298. ' weeklyplace: ' + 'null');
  299. _name.clear();
  300. _surname.clear();
  301. _mail.clear();
  302. _phoneNumber.clear();
  303. _address.clear();
  304. _username.clear();
  305. _passwd.clear();
  306. _passwd2.clear();
  307. }
  308. }
  309. }