Created
July 21, 2019 04:14
-
-
Save bugudiramu/45431fb0d333adf62ed5fb6d96a90cbd to your computer and use it in GitHub Desktop.
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
import 'package:flutter/material.dart'; | |
import 'package:font_awesome_flutter/font_awesome_flutter.dart'; | |
void main() { | |
runApp( | |
MaterialApp( | |
theme: ThemeData(fontFamily: "Montserrat"), | |
home: Login(), | |
debugShowCheckedModeBanner: false, | |
), | |
); | |
} | |
// ************* Login ************************** | |
class Login extends StatefulWidget { | |
@override | |
_LoginState createState() => _LoginState(); | |
} | |
class _LoginState extends State<Login> with SingleTickerProviderStateMixin { | |
GlobalKey<FormState> _formKey = GlobalKey<FormState>(); | |
TextEditingController _emailController = TextEditingController(); | |
TextEditingController _passwordController = TextEditingController(); | |
bool hidePass = true; | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
body: Container( | |
decoration: BoxDecoration( | |
gradient: LinearGradient( | |
begin: Alignment.bottomRight, | |
end: Alignment.topLeft, | |
stops: [0.5, 0.8], | |
colors: [ | |
Colors.cyanAccent, | |
Colors.tealAccent, | |
], | |
), | |
), | |
padding: const EdgeInsets.all(15.0), | |
child: Center( | |
child: ListView( | |
children: <Widget>[ | |
SizedBox( | |
height: 20.0, | |
), | |
Container( | |
padding: EdgeInsets.fromLTRB(0, 0, 0, 10), | |
alignment: Alignment.center, | |
child: Text( | |
"LogIn", | |
style: TextStyle( | |
fontSize: 40.0, | |
fontWeight: FontWeight.bold, | |
color: Color(0xFFB33771), | |
), | |
), | |
), | |
SizedBox(height: 30.0), | |
Form( | |
key: _formKey, | |
autovalidate: true, | |
child: Column( | |
children: <Widget>[ | |
TextFormField( | |
controller: _emailController, | |
keyboardType: TextInputType.emailAddress, | |
decoration: InputDecoration( | |
prefixIcon: Icon(Icons.alternate_email, | |
color: Colors.blueGrey), | |
hintText: "Email", | |
labelStyle: TextStyle( | |
// color: Colors.white, | |
), | |
labelText: "Email"), | |
validator: (val) { | |
if (val.isEmpty) { | |
return "Please Provide Email"; | |
} | |
return null; | |
}, | |
onSaved: (val) { | |
_emailController.text = val; | |
}, | |
autocorrect: true, | |
), | |
SizedBox( | |
height: 10.0, | |
), | |
TextFormField( | |
controller: _passwordController, | |
// obscureText:hidepass we toggle when user clicks the icon | |
obscureText: hidePass, | |
decoration: InputDecoration( | |
prefixIcon: Icon( | |
Icons.lock, | |
color: Colors.blueGrey, | |
), | |
suffixIcon: IconButton( | |
icon: Icon( | |
Icons.remove_red_eye, | |
color: Colors.blueGrey, | |
), | |
onPressed: () { | |
setState(() { | |
hidePass = false; | |
}); | |
}, | |
), | |
hintText: "Password", | |
labelText: "Password"), | |
validator: (val) { | |
if (val.length < 6) { | |
return "Passsword must contain atleast 6 characters"; | |
} else if (val.isEmpty) { | |
return "Password field can't be empty"; | |
} | |
return null; | |
}, | |
onSaved: (val) { | |
_passwordController.text = val; | |
}, | |
autocorrect: true, | |
), | |
SizedBox( | |
height: 20.0, | |
), | |
// ================== Login Btn ======================= | |
MaterialButton( | |
shape: RoundedRectangleBorder( | |
borderRadius: new BorderRadius.circular(25.0)), | |
minWidth: MediaQuery.of(context).size.width, | |
child: ListTile( | |
title: Center( | |
child: Text( | |
"Login", | |
style: _btnStyle(), | |
), | |
), | |
), | |
onPressed: () async { | |
print("login btn clicked!"); | |
signIn(); | |
}, | |
color: Color(0xFFB33771), | |
), | |
SizedBox( | |
height: 5.0, | |
), | |
Container( | |
child: Text( | |
"Forgot Password", | |
style: TextStyle( | |
decoration: TextDecoration.underline, | |
color: Color(0xFFB33771), | |
), | |
), | |
), | |
SizedBox( | |
height: 10.0, | |
), | |
Container( | |
child: Row( | |
mainAxisAlignment: MainAxisAlignment.center, | |
children: <Widget>[ | |
Text( | |
"Don't have an account!", | |
style: TextStyle( | |
color: Color(0xFFB33771), | |
), | |
), | |
SizedBox( | |
width: 10.0, | |
), | |
InkWell( | |
onTap: () => Navigator.of(context).push( | |
MaterialPageRoute( | |
builder: (context) => SignUp())), | |
child: Text("SignUp", | |
style: TextStyle( | |
fontWeight: FontWeight.bold, | |
color: Colors.blue, | |
fontSize: 18.0)), | |
), | |
], | |
), | |
), | |
], | |
), | |
), | |
], | |
), | |
), | |
), | |
); | |
} | |
TextStyle _btnStyle() { | |
return TextStyle( | |
color: Colors.white, | |
fontWeight: FontWeight.bold, | |
); | |
} | |
signIn() { | |
if (_formKey.currentState.validate()) { | |
_formKey.currentState.save(); | |
} | |
} | |
} | |
// ************************** SignUp ******************** | |
class SignUp extends StatefulWidget { | |
@override | |
_SignUpState createState() => _SignUpState(); | |
} | |
class _SignUpState extends State<SignUp> with SingleTickerProviderStateMixin { | |
GlobalKey<FormState> _formKey = GlobalKey<FormState>(); | |
TextEditingController _emailController = TextEditingController(); | |
TextEditingController _passwordController = TextEditingController(); | |
TextEditingController _confirmPasswordController = TextEditingController(); | |
TextEditingController _nameController = TextEditingController(); | |
bool hidePass = true; | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
body: Container( | |
decoration: BoxDecoration( | |
gradient: LinearGradient( | |
begin: Alignment.bottomRight, | |
end: Alignment.topLeft, | |
stops: [0.5, 0.8], | |
colors: [ | |
Colors.cyanAccent, | |
Colors.tealAccent, | |
], | |
), | |
), | |
padding: const EdgeInsets.all(15.0), | |
child: Center( | |
child: ListView( | |
children: <Widget>[ | |
InkWell( | |
child: Container( | |
alignment: Alignment.topLeft, | |
child: IconButton( | |
icon: Icon(FontAwesomeIcons.arrowLeft), | |
onPressed: () { | |
Navigator.of(context).pop(); | |
}, | |
), | |
), | |
), | |
SizedBox( | |
height: 10.0, | |
), | |
Container( | |
padding: EdgeInsets.fromLTRB(0, 0, 0, 10), | |
alignment: Alignment.center, | |
child: Text( | |
"SignUp", | |
style: TextStyle( | |
fontSize: 40.0, | |
fontWeight: FontWeight.bold, | |
color: Color(0xFFB33771), | |
), | |
), | |
), | |
SizedBox(height: 30.0), | |
Form( | |
key: _formKey, | |
autovalidate: true, | |
child: Column( | |
children: <Widget>[ | |
TextFormField( | |
controller: _nameController, | |
decoration: InputDecoration( | |
prefixIcon: Icon(Icons.supervised_user_circle, | |
color: Colors.blueGrey), | |
hintText: "Username", | |
labelText: "Username", | |
), | |
validator: (val) { | |
if (val.isEmpty) { | |
return "Please Provide Username"; | |
} | |
return null; | |
}, | |
onSaved: (val) { | |
_emailController.text = val; | |
}, | |
autocorrect: true, | |
), | |
SizedBox( | |
height: 10.0, | |
), | |
TextFormField( | |
controller: _emailController, | |
keyboardType: TextInputType.emailAddress, | |
decoration: InputDecoration( | |
prefixIcon: Icon(Icons.alternate_email, | |
color: Colors.blueGrey), | |
hintText: "Email", | |
labelStyle: TextStyle(), | |
labelText: "Email"), | |
validator: (val) { | |
if (val.isEmpty) { | |
return "Please Provide Email"; | |
} | |
return null; | |
}, | |
onSaved: (val) { | |
_emailController.text = val; | |
}, | |
autocorrect: true, | |
), | |
SizedBox( | |
height: 10.0, | |
), | |
TextFormField( | |
controller: _passwordController, | |
obscureText: hidePass, | |
decoration: InputDecoration( | |
suffixIcon: IconButton( | |
icon: Icon( | |
Icons.remove_red_eye, | |
color: Colors.blueGrey, | |
), | |
onPressed: () { | |
setState(() { | |
hidePass = false; | |
}); | |
}, | |
), | |
prefixIcon: Icon( | |
Icons.lock, | |
color: Colors.blueGrey, | |
), | |
hintText: "Password", | |
labelText: "Password"), | |
validator: (val) { | |
if (val.length < 6) { | |
return "Passsword must contain atleast 6 characters"; | |
} | |
return null; | |
}, | |
onSaved: (val) { | |
_passwordController.text = val; | |
}, | |
autocorrect: true, | |
), | |
SizedBox( | |
height: 10.0, | |
), | |
TextFormField( | |
controller: _confirmPasswordController, | |
obscureText: hidePass, | |
decoration: InputDecoration( | |
suffixIcon: IconButton( | |
icon: Icon( | |
Icons.remove_red_eye, | |
color: Colors.blueGrey, | |
), | |
onPressed: () { | |
setState(() { | |
hidePass = false; | |
}); | |
}, | |
), | |
prefixIcon: Icon( | |
Icons.lock, | |
color: Colors.blueGrey, | |
), | |
hintText: "Confirm Password", | |
labelText: "Confirm Password"), | |
validator: (val) { | |
if (val.length < 6) { | |
return "Passsword must contain atleast 6 characters"; | |
} else if (val.isEmpty) { | |
return "Password field can't be empty"; | |
} else if (_passwordController.text != val) { | |
return "Password and Confirm Password didn't match"; | |
} | |
return null; | |
}, | |
onSaved: (val) { | |
_passwordController.text = val; | |
}, | |
autocorrect: true, | |
), | |
SizedBox( | |
height: 20.0, | |
), | |
// ================== Login Btn ======================= | |
Container( | |
child: Column( | |
children: <Widget>[ | |
MaterialButton( | |
shape: RoundedRectangleBorder( | |
borderRadius: new BorderRadius.circular(25.0), | |
), | |
minWidth: MediaQuery.of(context).size.width, | |
child: ListTile( | |
title: Center( | |
child: Text( | |
"Signup For Free", | |
style: _btnStyle(), | |
), | |
), | |
), | |
onPressed: () {}, | |
color: Color(0xFFB33771), | |
), | |
SizedBox( | |
height: 5.0, | |
), | |
Container( | |
child: Text("OR"), | |
), | |
SizedBox( | |
height: 5.0, | |
), | |
// ================== Signin with Google Btn ======================= | |
MaterialButton( | |
shape: RoundedRectangleBorder( | |
borderRadius: new BorderRadius.circular(25.0)), | |
minWidth: MediaQuery.of(context).size.width, | |
child: ListTile( | |
leading: Image.asset( | |
"images/google.png", | |
height: 30.0, | |
), | |
title: Text( | |
"SignIn With Google", | |
style: _btnStyle(), | |
), | |
), | |
onPressed: () {}, | |
color: Colors.redAccent, | |
), | |
], | |
), | |
), | |
], | |
), | |
), | |
], | |
), | |
), | |
), | |
); | |
} | |
TextStyle _btnStyle() { | |
return TextStyle( | |
color: Colors.white, | |
fontWeight: FontWeight.bold, | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment