| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341 |
- import 'package:flutter/material.dart';
- import 'package:physigo/Services/AuthService.dart';
- //Fields..
- TextEditingController _name = TextEditingController();
- TextEditingController _surname = TextEditingController();
- TextEditingController _mail = TextEditingController();
- TextEditingController _phoneNumber = TextEditingController();
- TextEditingController _address = TextEditingController();
- TextEditingController _username = TextEditingController();
- TextEditingController _passwd = TextEditingController();
- TextEditingController _passwd2 = TextEditingController();
- bool anonymous = false;
- String? _dateString;
- final AuthenticationServices _auth = AuthenticationServices();
- class SignupPage extends StatefulWidget {
- const SignupPage({Key? key}) : super(key: key);
- @override
- State<SignupPage> createState() => _SignupPageState();
- }
- class _SignupPageState extends State<SignupPage> {
- int _pageIndex = 0;
- List<Widget> forms = [
- SignupForm1(
- title: '',
- ),
- SignupForm2(
- title: '',
- ),
- SignupForm3(
- title: '',
- )
- ];
- void _updatePageIndex(int newPageIndex) {
- if (newPageIndex == -1) {
- Navigator.pushNamed(context, '/');
- } else if (newPageIndex == 3) {
- //autentification
- //Navigator.pop(context);
- newPageIndex == 2;
- } else {
- setState(() {
- _pageIndex = newPageIndex;
- });
- }
- }
- @override
- Widget build(BuildContext context) {
- return Scaffold(
- floatingActionButton: Row(
- mainAxisAlignment: MainAxisAlignment.end,
- children: [
- FloatingActionButton(
- heroTag: "btn1",
- child: Icon(Icons.navigate_before_outlined),
- onPressed: () => _updatePageIndex(_pageIndex - 1)),
- SizedBox(
- width: 25,
- ),
- FloatingActionButton(
- heroTag: "btn2",
- child: Icon(Icons.navigate_next_outlined),
- onPressed: () => _updatePageIndex(_pageIndex + 1))
- ],
- ),
- body: Center(child: forms[_pageIndex]),
- );
- }
- }
- class SignupForm1 extends StatefulWidget {
- const SignupForm1({Key? key, required this.title}) : super(key: key);
- final String title;
- @override
- //_RegisterScreen createState() => _RegisterScreen();
- State<SignupForm1> createState() => _SignupForm1();
- }
- class _SignupForm1 extends State<SignupForm1> {
- DateTime? _dateTime;
- @override
- Widget build(BuildContext context) {
- return Scaffold(
- appBar: AppBar(
- title: const Text('Register Screen'),
- ),
- body: Center(
- child: SizedBox(
- width: 300,
- child: Column(children: <Widget>[
- const SizedBox(height: 30),
- Text(
- 'Personal Information',
- style: TextStyle(fontSize: 25, fontWeight: FontWeight.bold),
- ),
- const SizedBox(height: 30),
- Image.asset(
- 'assets/user.png',
- width: 150,
- ),
- const SizedBox(height: 30),
- TextFormField(
- controller: _name,
- decoration: InputDecoration(
- hintText: 'Name',
- ),
- ),
- const SizedBox(height: 10),
- TextFormField(
- controller: _surname,
- decoration: InputDecoration(
- hintText: 'Surname',
- ),
- ),
- const SizedBox(height: 10),
- Row(children: <Widget>[
- Text(_dateString == null
- ? 'Select birthday date :'
- : _dateString.toString()),
- const SizedBox(width: 49),
- ElevatedButton(
- onPressed: () {
- showDatePicker(
- context: context,
- initialDate: DateTime.now(),
- firstDate: DateTime(1900),
- lastDate: DateTime.now())
- .then((date) {
- setState(() {
- _dateTime = date!;
- _dateString = "${date.day}-${date.month}-${date.year}";
- });
- });
- },
- child: const Text('Select date'),
- ),
- ]),
- const SizedBox(height: 10),
- ]),
- )),
- );
- }
- }
- class SignupForm2 extends StatefulWidget {
- const SignupForm2({Key? key, required this.title}) : super(key: key);
- final String title;
- @override
- //_RegisterScreen createState() => _RegisterScreen();
- State<SignupForm2> createState() => _SignupForm2();
- }
- class _SignupForm2 extends State<SignupForm2> {
- @override
- Widget build(BuildContext context) {
- return Scaffold(
- appBar: AppBar(
- title: const Text('Register Screen'),
- ),
- body: Center(
- child: SizedBox(
- width: 300,
- child: Column(children: <Widget>[
- const SizedBox(height: 30),
- Text(
- 'Contact Details',
- style: TextStyle(fontSize: 25, fontWeight: FontWeight.bold),
- ),
- const SizedBox(height: 30),
- Image.asset(
- 'assets/communicate.png',
- width: 150,
- ),
- const SizedBox(height: 30),
- TextFormField(
- controller: _mail,
- decoration: InputDecoration(
- hintText: 'Mail',
- ),
- ),
- const SizedBox(height: 10),
- TextFormField(
- controller: _phoneNumber,
- decoration: InputDecoration(
- hintText: 'Phone Number',
- ),
- ),
- const SizedBox(height: 10),
- TextFormField(
- controller: _address,
- decoration: InputDecoration(
- hintText: 'Home Adress..',
- ),
- ),
- const SizedBox(height: 10),
- Row(children: <Widget>[
- Text('Anonymous'),
- Checkbox(
- checkColor: Colors.white,
- value: anonymous,
- onChanged: (bool? value) {
- setState(() {
- anonymous = value!;
- });
- },
- ),
- ]),
- const SizedBox(height: 10),
- ]),
- )),
- );
- }
- }
- class SignupForm3 extends StatefulWidget {
- const SignupForm3({Key? key, required this.title}) : super(key: key);
- final String title;
- @override
- //_RegisterScreen createState() => _RegisterScreen();
- State<SignupForm3> createState() => _SignupForm3();
- }
- class _SignupForm3 extends State<SignupForm3> {
- @override
- Widget build(BuildContext context) {
- return Scaffold(
- appBar: AppBar(
- title: const Text('Register Screen'),
- ),
- body: Center(
- child: SizedBox(
- width: 300,
- child: Column(children: <Widget>[
- const SizedBox(height: 30),
- Text(
- 'User details',
- style: TextStyle(fontSize: 25, fontWeight: FontWeight.bold),
- ),
- const SizedBox(height: 30),
- Image.asset(
- 'assets/id-card.png',
- width: 150,
- ),
- const SizedBox(height: 30),
- TextFormField(
- controller: _username,
- decoration: InputDecoration(
- hintText: 'Username',
- ),
- ),
- const SizedBox(height: 10),
- TextFormField(
- controller: _passwd,
- obscureText: true,
- enableSuggestions: false,
- autocorrect: false,
- decoration: InputDecoration(
- hintText: 'Password',
- ),
- ),
- const SizedBox(height: 10),
- TextFormField(
- controller: _passwd2,
- obscureText: true,
- enableSuggestions: false,
- autocorrect: false,
- decoration: InputDecoration(
- hintText: 'Repeat password',
- ),
- ),
- const SizedBox(height: 15),
- ElevatedButton(
- onPressed: () {
- try {
- if (_passwd.text == _passwd2.text) {
- createUser();
- Navigator.pop(context);
- } else {
- print("passwd is not the same");
- }
- } catch (e) {
- print(e.toString());
- }
- },
- child: const Text('Finish Register')),
- ]),
- )),
- );
- }
- void createUser() async {
- dynamic result =
- await _auth.createNewUser(_address.text, anonymous, _dateString.toString(), _name.text, _mail.text, _passwd.text,
- _phoneNumber.text, _username.text, _surname.text);
- if (result == null) {
- print('mail not valid');
- } else {
- //print(result.toString());
- //[51.787378° N, 19.449455° E]
- print('***** address: ' + _address.text +
- ' anonymous: ' + anonymous.toString() +
- ' birthdate: ' + _dateString.toString() +
- ' createDate: ' + DateTime.now().toString()+
- ' last_challenge_data: ' + 'null'+
- ' mail: ' + _mail.text +
- ' name: ' + _name.text +
- ' passwd: ' + '??? ' +
- ' phone_number: ' + _phoneNumber.text+
- ' shared_id: ' + _username.text +
- ' surname: ' + _surname.text +
- ' totalpoints: 0 ' +
- ' update_date: ' + DateTime.now().toString()+
- ' weeklyplace: ' + 'null');
- _name.clear();
- _surname.clear();
- _mail.clear();
- _phoneNumber.clear();
- _address.clear();
- _username.clear();
- _passwd.clear();
- _passwd2.clear();
- }
- }
- }
|