Commit 0b3bbbad authored by NirmalaSudhir's avatar NirmalaSudhir
Browse files

checking in working base code For sign up UI along with firebase

parent 36431969
import 'package:firebase_database/firebase_database.dart';
class UserServices{
FirebaseDatabase _database = FirebaseDatabase.instance;
String ref = "users";
createUser(String uid,Map value) {
_database.reference().child("$ref/$uid").push().set(
value
).catchError((e)=> { print(e.toString())});
}
}
\ No newline at end of file
......@@ -7,6 +7,9 @@ import 'package:my_kart_flash_app/screens/login.dart';
void main() => runApp(
MaterialApp(
debugShowCheckedModeBanner: false,
theme: ThemeData(
primaryColor: Colors.red.shade900
),
home: Login(),
));
......@@ -3,6 +3,7 @@ import 'package:flutter/material.dart';
import 'package:carousel_pro/carousel_pro.dart';
import 'package:flutter/widgets.dart';
import 'package:my_kart_flash_app/screens/categories_list_view.dart';
import 'package:my_kart_flash_app/screens/login.dart';
import 'package:my_kart_flash_app/screens/myCart.dart';
import 'package:my_kart_flash_app/screens/products.dart';
class HomePage extends StatefulWidget {
......@@ -120,6 +121,16 @@ class _HomePageState extends State<HomePage> {
leading: Icon(Icons.help, color: Colors.blue),
),
),
InkWell(
onTap: (){
Navigator.push(context, MaterialPageRoute(builder: (context) => new Login()));
},
child: ListTile(
title: Text('Logout'),
leading: Icon(Icons.exit_to_app, color: Colors.blue),
),
),
],
),
),
......
......@@ -4,6 +4,7 @@ import 'package:flutter/material.dart';
import 'package:firebase_auth/firebase_auth.dart';
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:my_kart_flash_app/screens/homepage.dart';
import 'package:my_kart_flash_app/screens/signup.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:google_sign_in/google_sign_in.dart';
import 'package:fluttertoast/fluttertoast.dart';
......@@ -115,7 +116,7 @@ class _LoginState extends State<Login> {
height: double.infinity,
),
Container(
color: Colors.white.withOpacity(0.2),
color: Colors.black.withOpacity(0.4),
width: double.infinity,
height: double.infinity,
),
......@@ -124,7 +125,7 @@ class _LoginState extends State<Login> {
child: Center(
child: Form(
key: _formKey,
child: Column(
child: ListView(
children: <Widget>[
Padding(
padding: const EdgeInsets.all(8.0),
......@@ -161,7 +162,7 @@ class _LoginState extends State<Login> {
child: Material(
borderRadius: BorderRadius.circular(20.0),
color: Colors.white.withOpacity(0.5),
elevation:0.0,
elevation:0.0,
child: Padding(
padding: const EdgeInsets.only(left: 12.0),
child: TextFormField(
......@@ -197,9 +198,36 @@ class _LoginState extends State<Login> {
),
),
),
Padding(
padding: const EdgeInsets.all(8.0),
child: Text("Forgot Password", textAlign: TextAlign.center, style: TextStyle(color: Colors.white,fontWeight: FontWeight.bold),),
),
Padding(
padding: const EdgeInsets.all(8.0),
/*child: RichText(text: TextSpan(
style: TextStyle(color:Colors.white,fontWeight: FontWeight.w700,fontSize: 16.0),
children: [
TextSpan(
text: "Don't have an account? click here to"
),
TextSpan(
text: "Sign Up!",
style: TextStyle(color: Colors.green,fontWeight: FontWeight.w700,fontSize: 16.0)
)
]
)),*/
child: InkWell(
onTap:(){
Navigator.push(context, MaterialPageRoute(builder: (context) => SignUp()));
},
child: Text("Sign up", textAlign: TextAlign.center,style: TextStyle(color: Colors.red,fontWeight: FontWeight.bold)),
)
),
Expanded(child: Container(),),
Divider(color:Colors.white),
Text("Other Login Options",style: TextStyle(color:Colors.white,fontWeight: FontWeight.bold)),
Text("Other Login Options", textAlign: TextAlign.center,style: TextStyle(color:Colors.white,fontWeight: FontWeight.bold)),
Padding(
padding: const EdgeInsets.all(8.0),
child: Material(
......
......@@ -123,7 +123,7 @@ class _ProductDetailsState extends State<ProductDetails> {
content: new Text("Choose your color"),
actions: <Widget>[
new MaterialButton(onPressed: (){
Navigator.of(context).pop(context);
Navigator.of(context).pop(context);
},
child: new Text("Close"),
)
......@@ -233,7 +233,9 @@ class _ProductDetailsState extends State<ProductDetails> {
// Buy and Add to Favourites button code Goes here
Row(
/*Row(
children: <Widget>[
Expanded(
child: MaterialButton(
......@@ -248,13 +250,31 @@ class _ProductDetailsState extends State<ProductDetails> {
new IconButton(icon: Icon(Icons.favorite_border,color: Colors.red,),)
],
),
),*/
////////////////////
// Buy and Add to Favourites button code Ends here
],
),
floatingActionButton: new Stack(
bottomNavigationBar: Container(
child: Row(
children: <Widget>[
Expanded(
child: MaterialButton(
onPressed: (){},
color: Colors.red,
textColor: Colors.white,
elevation: 0.2,
child: new Text("Buy Now"),
),
),
new IconButton(icon: Icon(Icons.add_shopping_cart,color: Colors.red,),),
new IconButton(icon: Icon(Icons.favorite_border,color: Colors.red,),)
],
),
),
/*floatingActionButton: new Stack(
children: <Widget>[
new FloatingActionButton(
onPressed: (){
......@@ -274,7 +294,7 @@ class _ProductDetailsState extends State<ProductDetails> {
)
],
),
),*/
);
}
}
......
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:firebase_auth/firebase_auth.dart';
import 'package:flutter/material.dart';
import 'package:my_kart_flash_app/db/users.dart';
import 'package:my_kart_flash_app/screens/homepage.dart';
import 'package:shared_preferences/shared_preferences.dart';
class SignUp extends StatefulWidget {
@override
_SignUpState createState() => _SignUpState();
}
class _SignUpState extends State<SignUp> {
final FirebaseAuth firebaseAuth = FirebaseAuth.instance;
final FirebaseAuth _auth = FirebaseAuth.instance;
FirebaseAuth auth = FirebaseAuth.instance;
UserServices _userServices = UserServices();
final _formKey = GlobalKey<FormState>();
TextEditingController _emailTextController = TextEditingController();
TextEditingController _nameTextController = TextEditingController();
TextEditingController _passwordTextController = TextEditingController();
TextEditingController _confirmpasswordTextController = TextEditingController();
String gender;
String groupValue ="male";
bool hidePass =true;
SharedPreferences preferences;
bool loading = false;
@override
Widget build(BuildContext context) {
return Scaffold(
body: new Stack(
children: <Widget>[
Image.asset(
'images/login_background/redDress.jpg',
fit: BoxFit.cover,
width: double.infinity,
height: double.infinity,
),
Container(
color: Colors.black.withOpacity(0.4),
width: double.infinity,
height: double.infinity,
),
Padding(
padding: const EdgeInsets.only(top:200.0),
child: Center(
child: Form(
key: _formKey,
child: ListView(
children: <Widget>[
Padding(
padding: const EdgeInsets.all(8.0),
child: Material(
borderRadius: BorderRadius.circular(20.0),
color: Colors.white.withOpacity(0.5),
elevation:0.0,
child: Padding(
padding: const EdgeInsets.only(left:12.0),
child: TextFormField(
controller: _emailTextController,
decoration: InputDecoration(
hintText: "Email",
icon: Icon(Icons.email)
),
validator: (value){
if(value.isEmpty){
Pattern pattern =
r'^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$';
RegExp regex = new RegExp(pattern);
if(!regex.hasMatch(value))
return 'Please make sure your email address is valid';
else
return null;
}
},
),
),
),
),
Padding(
// padding: const EdgeInsets.fromLTRB(14.0, 8.0, 14.0, 8.0),
padding: const EdgeInsets.all(8.0),
child: Material(
borderRadius: BorderRadius.circular(20.0),
color: Colors.white.withOpacity(0.5),
elevation:0.0,
child: Padding(
padding: const EdgeInsets.only(left: 12.0),
child: TextFormField(
controller: _nameTextController,
decoration: InputDecoration(
border: InputBorder.none,
hintText: "Name",
icon: Icon(Icons.perm_identity),
),
validator: (value) {
if (value.isEmpty) {
return "The Name field cannot be empty";
}
return null;
},
),
),
),
),
Padding(
padding: const EdgeInsets.fromLTRB(14.0,12.0,12.0,12.0),
child: new Container(
color: Colors.white.withOpacity(0.5),
child: Row(
children: <Widget>[
Expanded(
child: ListTile(
title: Text(
"Male",
style: TextStyle(
color: Colors.white70
),
),
trailing:Radio(
value: "male",
groupValue: groupValue,
onChanged: (e) => valueChanged(e)),
)
),
Expanded(
child: ListTile(
title: Text(
"Female",
style: TextStyle(
color: Colors.white70
),
),
trailing:Radio(
value: "female",
groupValue: groupValue,
onChanged: (e) => valueChanged(e)),
)
),
],
),
),
),
Padding(
// padding: const EdgeInsets.fromLTRB(14.0, 8.0, 14.0, 8.0),
padding: const EdgeInsets.all(8.0),
child: Material(
borderRadius: BorderRadius.circular(20.0),
color: Colors.white.withOpacity(0.5),
elevation:0.0,
child: Padding(
padding: const EdgeInsets.only(left: 12.0),
child: ListTile(
title: TextFormField(
controller: _passwordTextController,
obscureText: hidePass,
decoration: InputDecoration(
border: InputBorder.none,
hintText: "Password",
icon: Icon(Icons.lock_outline),
),
validator: (value) {
if (value.isEmpty) {
return "The password field cannot be empty";
} else if (value.length < 6) {
return "the password has to be at least 6 characters long";
}
return null;
},
),
trailing: IconButton(icon: Icon(Icons.remove_red_eye), onPressed: (){
setState(() {
hidePass = false;
});
},),
),
),
),
),
Padding(
// padding: const EdgeInsets.fromLTRB(14.0, 8.0, 14.0, 8.0),
padding: const EdgeInsets.all(8.0),
child: Material(
borderRadius: BorderRadius.circular(20.0),
color: Colors.white.withOpacity(0.5),
elevation:0.0,
child: Padding(
padding: const EdgeInsets.only(left: 12.0),
child: ListTile(
title: TextFormField(
controller: _confirmpasswordTextController ,
obscureText: hidePass ,
decoration: InputDecoration(
border: InputBorder.none ,
hintText: "Confirm Password" ,
icon: Icon( Icons.lock_outline ) ,
) ,
validator: ( value ) {
if ( value.isEmpty ) {
return "The password field cannot be empty";
} else if ( value.length < 6 ) {
return "the password has to be at least 6 characters long";
} else
if ( _passwordTextController.text != value ) {
return "the passwords do not match";
}
return null;
} ,
) ,
trailing: IconButton(
icon: Icon( Icons.remove_red_eye ) ,
onPressed: ( ) {
setState( ( ) {
hidePass = false;
} );
} , ) ,
),
),
),
),
Padding(
padding: const EdgeInsets.all(8.0),
child: Material(
borderRadius: BorderRadius.circular(20.0),
color: Colors.blueAccent,
elevation: 0.0,
child: MaterialButton(onPressed: (){
validateForm();
},
minWidth: MediaQuery.of(context).size.width,
child: Text("Sign Up",textAlign: TextAlign.center,
style: TextStyle(color:Colors.white,fontWeight: FontWeight.bold),
),
),
),
),
Padding(
padding: const EdgeInsets.all(8.0),
child: InkWell(
onTap: (){
Navigator.pop(context);
},
child: Text("Login", textAlign: TextAlign.center,style: TextStyle(color: Colors.red,fontSize: 18.0,fontWeight: FontWeight.w700)),
),
),
],
)
),
),
),
Visibility(
visible: loading ?? true,
child: Center(
child: Container(
alignment: Alignment.center,
color: Colors.white.withOpacity(0.7),
child: CircularProgressIndicator(
valueColor: AlwaysStoppedAnimation<Color>(Colors.red),
),
),
),
)
],
),
/*bottomNavigationBar: Container(
child : Padding(
padding: const EdgeInsets.only(left:12.0, right:12.0,top:8.0, bottom: 8.0),
child: FlatButton(
color: Colors.red,
onPressed: (){
handleSignIn();
},child: Text("Sign In / Sign Up with Google",style: TextStyle(color: Colors.white70),)),
),
),*/
);
}
valueChanged(e) {
setState(() {
if(e == "male"){
groupValue = e;
gender = e;
}else if(e == "female"){
groupValue = e;
gender = e;
}
});
}
void validateForm() async{
FormState formState = _formKey.currentState;
Map value;
if(formState.validate()){
FirebaseUser user = await firebaseAuth.currentUser();
if (user == null){
/*firebaseAuth.createUserWithEmailAndPassword(
email: _emailTextController.text,
password: _passwordTextController.text,).then((user) => (){
_userServices.createUser({
"username": user.Name,
"email": user.email,
} );
});*/
FirebaseAuth.instance.createUserWithEmailAndPassword (
email: _emailTextController.text ,
password: _passwordTextController.text ).then ( ( authResult ) =>
Firestore.instance.collection ( "users" ).document (
authResult.user.uid ).setData ( {
"username": authResult.user.displayName ,
"email": authResult.user.email ,
"userId": authResult.user.uid ,
"gender": gender ,
// "password" : _passwordTextController.text,
} ) ).catchError((err) => {print(err.toString())});
Navigator.pushReplacement(context, MaterialPageRoute(builder:(context) => HomePage()));
}
}
}
}
......@@ -106,6 +106,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.4"
firebase_database:
dependency: "direct main"
description:
name: firebase_database
url: "https://pub.dartlang.org"
source: hosted
version: "3.1.3"
flutter:
dependency: "direct main"
description: flutter
......
......@@ -29,6 +29,7 @@ dependencies:
google_sign_in: ^4.0.0
shared_preferences: ^0.5.5
fluttertoast: ^3.1.3
firebase_database: ^3.1.3
dev_dependencies:
flutter_test:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment