Aitrainer_app 1.1.0
Login and Registraion
This commit is contained in:
@@ -0,0 +1,81 @@
|
||||
|
||||
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),
|
||||
}
|
||||
})
|
||||
])
|
||||
),
|
||||
),
|
||||
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
|
||||
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 RegistrationPage extends StatefulWidget{
|
||||
_RegistrationPageState createState() => _RegistrationPageState();
|
||||
}
|
||||
|
||||
class _RegistrationPageState 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('Registration'),
|
||||
),
|
||||
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: (String input) {
|
||||
String rc = input.length < 4 ? 'Password too short.' : null;
|
||||
return rc;
|
||||
}, */
|
||||
onChanged: (input) => user.setPassword(input),
|
||||
obscureText: _obscureText,
|
||||
),
|
||||
new InkWell(
|
||||
child: new Text('I have an account'),
|
||||
onTap: () => Navigator.of(context).pushNamed('login'),
|
||||
),
|
||||
new FloatingActionButton(
|
||||
child: Icon(Icons.cloud_done,),
|
||||
onPressed:() => {
|
||||
if (_formKey.currentState.validate()) {
|
||||
model = UserChangingViewModel(user),
|
||||
model.addUser(),
|
||||
Navigator.pop(context),
|
||||
}
|
||||
}
|
||||
)
|
||||
])
|
||||
),
|
||||
),
|
||||
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user