142 lines
5.7 KiB
Dart
142 lines
5.7 KiB
Dart
|
|
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<RegistrationPage> {
|
|
final GlobalKey<ScaffoldState> _scaffoldKey = new GlobalKey<ScaffoldState>();
|
|
final UserViewModel user = UserViewModel();
|
|
bool _obscureText = true;
|
|
|
|
final _formKey = GlobalKey<FormState>();
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
UserChangingViewModel model = UserChangingViewModel(user);
|
|
CustomerChangingViewModel customerChangingViewModel = Provider.of<CustomerChangingViewModel>(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: <Widget>[
|
|
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: <Widget>[ 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: <Widget>[
|
|
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))
|
|
)
|
|
);
|
|
}
|
|
} |