import 'package:aitrainer_app/localization/app_localization.dart'; import 'package:aitrainer_app/model/auth.dart'; import 'package:aitrainer_app/viewmodel/customer_changing_view_model.dart'; import 'package:aitrainer_app/viewmodel/user_changing_view_model.dart'; import 'package:aitrainer_app/viewmodel/user_view_model.dart'; import 'package:flutter/material.dart'; import 'package:flutter/cupertino.dart'; import 'package:provider/provider.dart'; class RegistrationPage extends StatefulWidget{ _RegistrationPageState createState() => _RegistrationPageState(); } class _RegistrationPageState extends State { final GlobalKey _scaffoldKey = new GlobalKey(); final UserViewModel user = UserViewModel(); bool _obscureText = true; final _formKey = GlobalKey(); @override Widget build(BuildContext context) { UserChangingViewModel model = UserChangingViewModel(user); CustomerChangingViewModel customerChangingViewModel = Provider.of(context, listen: false); user.createNew(); return Scaffold( key: _scaffoldKey, body: Container( decoration: BoxDecoration( image: DecorationImage( image: AssetImage('asset/image/WT_login.png'), fit: BoxFit.cover, //height: double.infinity, //width: double.infinity, alignment: Alignment.center, ), ), child: Form( key: _formKey, child: Container( padding: const EdgeInsets.only (left:25, right: 100), child: Column( mainAxisAlignment: MainAxisAlignment.spaceAround, children: [ Spacer(flex:4), Row( mainAxisAlignment: MainAxisAlignment.start, children: [ new InkWell( child: new Text(AppLocalizations.of(context).translate('SignUp'), style: TextStyle(fontWeight: FontWeight.bold, fontSize: 24)), ), ], ), TextFormField( decoration: InputDecoration( fillColor: Colors.white, filled:true, labelText: 'Email', ), validator: (String input) { RegExp exp = new RegExp(r"[\w._]+\@[\w._]+.[a-z]+", caseSensitive: false, multiLine: false,); String ret = exp.hasMatch(input) == true ? null: AppLocalizations.of(context).translate('Please type an email address'); return ret; }, onChanged: (input) => user.setEmail(input), ), Spacer(flex:1), new TextFormField( decoration: const InputDecoration( filled:true, labelText: "Password", fillColor: Colors.white, focusColor: Colors.white, ), validator: (val) => val.length < 6 ? AppLocalizations.of(context).translate('Password too short') : null, obscureText: _obscureText, onChanged: (input) => user.setPassword(input), ), Spacer(flex:1), Row( mainAxisAlignment: MainAxisAlignment.end, children: [ new FlatButton( child: Image.asset('asset/image/WT_OK.png', width: 100, height:100 ), onPressed:() => { if (_formKey.currentState.validate()) { model = UserChangingViewModel(user), model.addUser().then((_) => { Navigator.of(context).pushNamed("customerModifyPage",), customerChangingViewModel.customer.setCustomer(Auth().userLoggedIn), }).catchError(( error, stackTrace )=> showInSnackBar() ), } }), ]), Spacer(flex:2), Row( mainAxisAlignment: MainAxisAlignment.spaceAround, children: [ new InkWell( child: new Text(AppLocalizations.of(context).translate('Login')), onTap: () => Navigator.of(context).pushNamed('login'), ), Spacer(flex:1), new InkWell( child: new Text(AppLocalizations.of(context).translate('Privacy')), onTap: () => Navigator.of(context).pushNamed('gdpr'), ), Spacer(flex:2), ]), Spacer(flex:2), ]) ), ), ), ); } void showInSnackBar() { _scaffoldKey.currentState.showSnackBar( SnackBar( backgroundColor: Colors.orange, content: Text( AppLocalizations.of(context).translate("Customer exists"), style: TextStyle(color: Colors.white)) ) ); } }