Skip to content

Commit

Permalink
Added Login and Register pages
Browse files Browse the repository at this point in the history
  • Loading branch information
JideGuru committed Jul 8, 2020
1 parent d63eb06 commit b93bc4c
Show file tree
Hide file tree
Showing 4 changed files with 280 additions and 2 deletions.
3 changes: 2 additions & 1 deletion lib/components/custom_text_field.dart
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ class CustomTextField extends StatelessWidget {
),
contentPadding: EdgeInsets.symmetric(horizontal: 20.0),
border: border(),
focusedBorder: border()
focusedBorder: border(),
disabledBorder: border()
),
),
);
Expand Down
5 changes: 4 additions & 1 deletion lib/screens/auth/check_email.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import 'package:flutter/material.dart';
import 'package:social_app_ui/components/custom_button.dart';
import 'package:social_app_ui/components/custom_text_field.dart';
import 'package:social_app_ui/screens/auth/login.dart';
import 'package:social_app_ui/util/const.dart';
import 'package:social_app_ui/util/router.dart';
import 'package:social_app_ui/util/validations.dart';

class CheckEmail extends StatefulWidget {
Expand All @@ -21,9 +23,10 @@ class _CheckEmailState extends State<CheckEmail> {
form.save();
if (!form.validate()) {
validate = true;
setState(() {});
showInSnackBar('Please fix the errors in red before submitting.');
}else{

Router.pushPage(context, Login(email: email,));
}
}

Expand Down
130 changes: 130 additions & 0 deletions lib/screens/auth/login.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
import 'package:flutter/material.dart';
import 'package:social_app_ui/components/custom_button.dart';
import 'package:social_app_ui/components/custom_text_field.dart';
import 'package:social_app_ui/screens/auth/register.dart';
import 'package:social_app_ui/util/const.dart';
import 'package:social_app_ui/util/router.dart';
import 'package:social_app_ui/util/validations.dart';

class Login extends StatefulWidget {
final String email;

Login({@required this.email});
@override
_LoginState createState() => _LoginState();
}

class _LoginState extends State<Login> {
bool loading = false;
bool validate = false;
GlobalKey<FormState> formKey = GlobalKey<FormState>();
GlobalKey<ScaffoldState> _scaffoldKey = GlobalKey<ScaffoldState>();
String email, password = '';
FocusNode emailFN = FocusNode();
FocusNode passFN = FocusNode();

login() async{
FormState form = formKey.currentState;
form.save();
if (!form.validate()) {
validate = true;
setState(() {});
showInSnackBar('Please fix the errors in red before submitting.');
}else{
Router.pushPage(context, Register(email: email,));
}
}

void showInSnackBar(String value) {
_scaffoldKey.currentState.removeCurrentSnackBar();
_scaffoldKey.currentState
.showSnackBar(SnackBar(content: Text(value)));
}

@override
Widget build(BuildContext context) {
return Scaffold(
key: _scaffoldKey,
body: Center(
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 20.0),
child: Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Hero(
tag: 'appname',
child: Material(
type: MaterialType.transparency,
child: Text(
'${Constants.appName}',
style: TextStyle(
fontSize: 40.0,
fontWeight: FontWeight.bold,
),
),
),
),

SizedBox(
height: 100.0,
),

Form(
autovalidate: validate,
key: formKey,
child: Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
CustomTextField(
enabled: false,
hintText: "jideguru@gmail.com",
textInputAction: TextInputAction.next,
validateFunction: Validations.validateEmail,
onSaved: (String val) {
email = val;
},
initialValue: widget.email,
focusNode: emailFN,
nextFocusNode: passFN,
),

SizedBox(
height: 20.0,
),

CustomTextField(
enabled: !loading,
hintText: "Password",
textInputAction: TextInputAction.done,
validateFunction: Validations.validatePassword,
submitAction: login,
obscureText: true,
onSaved: (String val) {
password = val;
},
focusNode: passFN,
),
],
),
),

SizedBox(
height: 40.0,
),
buildButton(),
],
),
),
),
);
}

buildButton() {
return loading
? Center(child: CircularProgressIndicator())
: CustomButton(
label: "Login",
onPressed: () => login(),
);
}
}
144 changes: 144 additions & 0 deletions lib/screens/auth/register.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
import 'package:flutter/material.dart';
import 'package:social_app_ui/components/custom_button.dart';
import 'package:social_app_ui/components/custom_text_field.dart';
import 'package:social_app_ui/util/const.dart';
import 'package:social_app_ui/util/validations.dart';

class Register extends StatefulWidget {
final String email;

Register({@required this.email});

@override
_RegisterState createState() => _RegisterState();
}

class _RegisterState extends State<Register> {
bool loading = false;
bool validate = false;
GlobalKey<FormState> formKey = GlobalKey<FormState>();
GlobalKey<ScaffoldState> _scaffoldKey = GlobalKey<ScaffoldState>();
String email, password, name = '';
FocusNode nameFN = FocusNode();
FocusNode emailFN = FocusNode();
FocusNode passFN = FocusNode();

login() async{
FormState form = formKey.currentState;
form.save();
if (!form.validate()) {
validate = true;
setState(() {});
showInSnackBar('Please fix the errors in red before submitting.');
}else{

}
}

void showInSnackBar(String value) {
_scaffoldKey.currentState.removeCurrentSnackBar();
_scaffoldKey.currentState
.showSnackBar(SnackBar(content: Text(value)));
}

@override
Widget build(BuildContext context) {
return Scaffold(
key: _scaffoldKey,
body: Center(
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 20.0),
child: Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Hero(
tag: 'appname',
child: Material(
type: MaterialType.transparency,
child: Text(
'${Constants.appName}',
style: TextStyle(
fontSize: 40.0,
fontWeight: FontWeight.bold,
),
),
),
),

SizedBox(
height: 100.0,
),

Form(
autovalidate: validate,
key: formKey,
child: Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
CustomTextField(
enabled: !loading,
hintText: "Name",
textInputAction: TextInputAction.next,
validateFunction: Validations.validateName,
onSaved: (String val) {
name = val;
},
focusNode: nameFN,
nextFocusNode: emailFN,
),
SizedBox(
height: 20.0,
),
CustomTextField(
enabled: false,
initialValue: widget.email,
hintText: "jideguru@gmail.com",
textInputAction: TextInputAction.next,
validateFunction: Validations.validateEmail,
onSaved: (String val) {
email = val;
},
focusNode: emailFN,
nextFocusNode: passFN,
),

SizedBox(
height: 20.0,
),

CustomTextField(
enabled: !loading,
hintText: "Password",
textInputAction: TextInputAction.done,
validateFunction: Validations.validatePassword,
submitAction: login,
obscureText: true,
onSaved: (String val) {
password = val;
},
focusNode: passFN,
),
],
),
),

SizedBox(
height: 40.0,
),
buildButton(),
],
),
),
),
);
}

buildButton() {
return loading
? Center(child: CircularProgressIndicator())
: CustomButton(
label: "Login",
onPressed: () => login(),
);
}
}

0 comments on commit b93bc4c

Please sign in to comment.