-
-
Notifications
You must be signed in to change notification settings - Fork 511
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
280 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(), | ||
); | ||
} | ||
} |