SignupPage.dart 9.4 KB

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