139 lines
6.0 KiB
Dart
139 lines
6.0 KiB
Dart
import 'package:aitrainer_app/localization/app_localization.dart';
|
|
import 'package:aitrainer_app/model/auth.dart';
|
|
import 'package:aitrainer_app/viewmodel/exercise_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 LoginPage extends StatefulWidget{
|
|
_LoginPageState createState() => _LoginPageState();
|
|
}
|
|
|
|
class _LoginPageState extends State {
|
|
final UserViewModel user = UserViewModel();
|
|
final bool _obscureText = true;
|
|
final _formKey = GlobalKey<FormState>();
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
UserChangingViewModel model = UserChangingViewModel(user);
|
|
ExerciseChangingViewModel exerciseModel = Provider.of<ExerciseChangingViewModel>(context, listen: false);
|
|
user.createNew();
|
|
|
|
return Scaffold(
|
|
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(
|
|
'Login'),
|
|
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.getUser(),
|
|
exerciseModel.setCustomer(
|
|
Auth().userLoggedIn),
|
|
Navigator.pop(context),
|
|
}
|
|
}),
|
|
]),
|
|
Spacer(flex: 2),
|
|
Row(
|
|
mainAxisAlignment: MainAxisAlignment.spaceAround,
|
|
children: <Widget>[
|
|
new InkWell(
|
|
child: new Text(
|
|
AppLocalizations.of(context).translate(
|
|
'SignUp')),
|
|
onTap: () =>
|
|
Navigator.of(context).pushNamed(
|
|
'registration'),
|
|
),
|
|
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),
|
|
])
|
|
),
|
|
),
|
|
)
|
|
);
|
|
}
|
|
} |