81 lines
3.1 KiB
Dart
81 lines
3.1 KiB
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:aitrainer_app/widgets/nav_drawer.dart';
|
|
|
|
class LoginPage extends StatefulWidget{
|
|
_LoginPageState createState() => _LoginPageState();
|
|
}
|
|
|
|
class _LoginPageState extends State {
|
|
final UserViewModel user = UserViewModel();
|
|
bool _obscureText = true;
|
|
|
|
final _formKey = GlobalKey<FormState>();
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
UserChangingViewModel model = UserChangingViewModel(user);
|
|
user.createNew();
|
|
return Scaffold(
|
|
drawer: NavDrawer(),
|
|
appBar: AppBar(
|
|
title: Text('Login'),
|
|
),
|
|
body: Center(
|
|
child: Form(
|
|
key: _formKey,
|
|
child: Column(
|
|
children: <Widget>[
|
|
TextFormField(
|
|
decoration: InputDecoration(
|
|
border: OutlineInputBorder(),
|
|
labelText: 'Email',
|
|
icon: const Padding(
|
|
padding:const EdgeInsets.only(left: 20.0, top: 50.0),
|
|
child: const Icon(Icons.people)
|
|
)
|
|
),
|
|
validator: (String input) {
|
|
RegExp exp = new RegExp(r"[\w._]+\@[\w._]+.[a-z]+",
|
|
caseSensitive: false,
|
|
multiLine: false,);
|
|
String ret = exp.hasMatch(input) == true ?
|
|
null:
|
|
"Please type an email address";
|
|
return ret;
|
|
},
|
|
onChanged: (input) => user.setEmail(input),
|
|
),
|
|
new TextFormField(
|
|
decoration: const InputDecoration(
|
|
labelText: 'Password',
|
|
icon: const Padding(
|
|
padding: const EdgeInsets.only(left: 20.0, top: 15.0),
|
|
child: const Icon(Icons.lock))),
|
|
validator: (val) => val.length < 6 ? 'Password too short.' : null,
|
|
obscureText: _obscureText,
|
|
onChanged: (input) => user.setPassword(input),
|
|
),
|
|
new InkWell(
|
|
child: new Text('SignUp'),
|
|
onTap: () => Navigator.of(context).pushNamed('registration'),
|
|
),
|
|
new FloatingActionButton(
|
|
child: Icon(Icons.cloud_done,),
|
|
onPressed:() => {
|
|
if (_formKey.currentState.validate()) {
|
|
model = UserChangingViewModel(user),
|
|
model.getUser(),
|
|
Navigator.pop(context),
|
|
}
|
|
})
|
|
])
|
|
),
|
|
),
|
|
|
|
);
|
|
}
|
|
} |