Commit 7dde6e07 authored by NirmalaSudhir's avatar NirmalaSudhir
Browse files

added google firebase which works in real device. Emulator login takes too much time

parent 114a9e52
......@@ -22,6 +22,8 @@ if (flutterVersionName == null) {
}
apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'
apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
......@@ -44,6 +46,7 @@ android {
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
multiDexEnabled true
}
buildTypes {
......@@ -64,4 +67,11 @@ dependencies {
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
// implementation 'com.google.firebase:firebase-analytics:17.0.5'
// implementation 'com.google.firebase:firebase-analytics:17.2.3'
implementation 'com.android.support:multidex:1.0.3'
// implementation 'com.google.firebase:firebase-core:16.0.1'
// implementation 'com.google.firebase:firebase-core:16.0.7' '
//implementation 'com.google.firebase:firebase-core'
//implementation 'androidx.multidex:multidex:2.0.1'
}
{
"project_info": {
"project_number": "377676435673",
"firebase_url": "https://flutter-redcart.firebaseio.com",
"project_id": "flutter-redcart",
"storage_bucket": "flutter-redcart.appspot.com"
},
"client": [
{
"client_info": {
"mobilesdk_app_id": "1:377676435673:android:078a548670bb33d0e5aec8",
"android_client_info": {
"package_name": "com.example.my_kart_flash_app"
}
},
"oauth_client": [
{
"client_id": "377676435673-5jsucinbu2auc69riirvce05ieeqtlsn.apps.googleusercontent.com",
"client_type": 1,
"android_info": {
"package_name": "com.example.my_kart_flash_app",
"certificate_hash": "ef17b341a9d692e7ae7265c16d37c14bd4d0fa61"
}
},
{
"client_id": "377676435673-f7hoi0thahtaa3l5if1fgsi6lg8hcf7o.apps.googleusercontent.com",
"client_type": 3
}
],
"api_key": [
{
"current_key": "AIzaSyAlRL_5gTWiheN4HBo4CpPmaJcSxGvH71Q"
}
],
"services": {
"appinvite_service": {
"other_platform_oauth_client": [
{
"client_id": "377676435673-f7hoi0thahtaa3l5if1fgsi6lg8hcf7o.apps.googleusercontent.com",
"client_type": 3
}
]
}
}
}
],
"configuration_version": "1"
}
\ No newline at end of file
......@@ -8,6 +8,7 @@ buildscript {
dependencies {
classpath 'com.android.tools.build:gradle:3.5.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'com.google.gms:google-services:4.3.3'
}
}
......
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:my_kart_flash_app/screens/login.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/products.dart';
void main() => runApp(
MaterialApp(
debugShowCheckedModeBanner: false,
home: HomePage(),
home: Login(),
));
class HomePage extends StatefulWidget {
@override
_HomePageState createState() => _HomePageState();
}
class _HomePageState extends State<HomePage> {
@override
Widget build(BuildContext context) {
Widget image_carousel = new Container(
height: 200.0,
child: new Carousel(
boxFit: BoxFit.cover,
images: [
AssetImage('images/carousel/carousel1.jpeg'),
AssetImage('images/carousel/carousel2.jpeg'),
AssetImage('images/carousel/carousel3.jpeg'),
AssetImage('images/carousel/carousel4.jpeg'),
AssetImage('images/carousel/carousel5.jpg')
],
autoplay: true,
animationCurve: Curves.fastOutSlowIn,
animationDuration: Duration(milliseconds: 10),
dotSize: 4.0,
dotColor: Colors.lightBlue,
indicatorBgPadding: 2.0,
)
);
return Scaffold(
appBar: new AppBar(
elevation: 0.0,
backgroundColor: Colors.red,
title: Text('MyKart'),
actions: <Widget>[
new IconButton(
icon: Icon(
Icons.search,color: Colors.white),
onPressed: (){
}),
new IconButton(
icon: Icon(
Icons.shopping_cart,color: Colors.white),
onPressed: (){
})
],
),
drawer: new Drawer(
child: new ListView(
children: <Widget>[
// Header
new UserAccountsDrawerHeader(
accountName: Text("Nirmala Sudhir"),
accountEmail: Text("nirmalasudhirr@gmail.com"),
currentAccountPicture: GestureDetector(
child: new CircleAvatar(
backgroundColor: Colors.grey,
child: Icon(Icons.person,color: Colors.white),
),
),
decoration: new BoxDecoration(
color: Colors.red
),
),
// Body
InkWell(
onTap: (){},
child: ListTile(
title: Text('Home'),
leading: Icon(Icons.home, color: Colors.lightBlue,),
),
),
InkWell(
onTap: (){},
child: ListTile(
title: Text('My Account'),
leading: Icon(Icons.person,color: Colors.lightBlue),
),
),
InkWell(
onTap: (){},
child: ListTile(
title: Text('My Orders'),
leading: Icon(Icons.shopping_basket,color: Colors.lightBlue),
),
),
InkWell(
onTap: (){},
child: ListTile(
title: Text('Categories'),
leading: Icon(Icons.category,color: Colors.lightBlue),
),
),
InkWell(
onTap: (){},
child: ListTile(
title: Text('Favourites'),
leading: Icon(Icons.favorite,color: Colors.lightBlue),
),
),
InkWell(
onTap: (){},
child: ListTile(
title: Text('Settings'),
leading: Icon(Icons.settings,color: Colors.lightBlue),
),
),
InkWell(
onTap: (){},
child: ListTile(
title: Text('About'),
leading: Icon(Icons.help, color: Colors.blue),
),
),
],
),
),
body: new ListView(
children: <Widget>[
image_carousel,
// Categories Begins
new Padding(
padding: const EdgeInsets.all(8.0),
child: new Text('Categories'),
),
//List of Categoreis Begins
Categories(),
//List of Categories Ends
// Recent Products Begins here
new Padding(
padding: const EdgeInsets.all(15.0),
child: new Text('Recent Products'),
),
Container(
height: 320.0,
child: Products(),
)
// Recent Products Ends here
],
),
);
}
}
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/myCart.dart';
import 'package:my_kart_flash_app/screens/products.dart';
class HomePage extends StatefulWidget {
@override
_HomePageState createState() => _HomePageState();
}
class _HomePageState extends State<HomePage> {
@override
Widget build(BuildContext context) {
Widget image_carousel = new Container(
height: 200.0,
child: new Carousel(
boxFit: BoxFit.cover,
images: [
AssetImage('images/carousel/carousel1.jpeg'),
AssetImage('images/carousel/carousel2.jpeg'),
AssetImage('images/carousel/carousel3.jpeg'),
AssetImage('images/carousel/carousel4.jpeg'),
AssetImage('images/carousel/carousel5.jpg')
],
autoplay: true,
animationCurve: Curves.fastOutSlowIn,
animationDuration: Duration(milliseconds: 10),
dotSize: 4.0,
dotColor: Colors.lightBlue,
indicatorBgPadding: 2.0,
dotBgColor: Colors.transparent,
)
);
return Scaffold(
appBar: new AppBar(
elevation: 0.0,
backgroundColor: Colors.red,
title: Text('RedCart'),
actions: <Widget>[
new IconButton(
icon: Icon(
Icons.search,color: Colors.white),
onPressed: (){
}),
new IconButton(
icon: Icon(
Icons.shopping_cart,color: Colors.white),
onPressed: (){
Navigator.push(context, MaterialPageRoute(builder: (context) => new MyCart()));
})
],
),
drawer: new Drawer(
child: new ListView(
children: <Widget>[
// Header
new UserAccountsDrawerHeader(
accountName: Text("Nirmala Sudhir"),
accountEmail: Text("nirmalasudhirr@gmail.com"),
currentAccountPicture: GestureDetector(
child: new CircleAvatar(
backgroundColor: Colors.grey,
child: Icon(Icons.person,color: Colors.white),
),
),
decoration: new BoxDecoration(
color: Colors.red
),
),
// Body
InkWell(
onTap: (){},
child: ListTile(
title: Text('Home'),
leading: Icon(Icons.home, color: Colors.lightBlue,),
),
),
InkWell(
onTap: (){},
child: ListTile(
title: Text('My Account'),
leading: Icon(Icons.person,color: Colors.lightBlue),
),
),
InkWell(
onTap: (){},
child: ListTile(
title: Text('My Orders'),
leading: Icon(Icons.shopping_basket,color: Colors.lightBlue),
),
),
InkWell(
onTap: (){},
child: ListTile(
title: Text('Categories'),
leading: Icon(Icons.category,color: Colors.lightBlue),
),
),
InkWell(
onTap: (){},
child: ListTile(
title: Text('Favourites'),
leading: Icon(Icons.favorite,color: Colors.lightBlue),
),
),
InkWell(
onTap: (){},
child: ListTile(
title: Text('Settings'),
leading: Icon(Icons.settings,color: Colors.lightBlue),
),
),
InkWell(
onTap: (){},
child: ListTile(
title: Text('About'),
leading: Icon(Icons.help, color: Colors.blue),
),
),
],
),
),
body: new ListView(
children: <Widget>[
Divider(),
image_carousel,
// Categories Begins
new Padding(
padding: const EdgeInsets.all(8.0),
child: new Text('Categories'),
),
//List of Categoreis Begins
Categories(),
//List of Categories Ends
// Recent Products Begins here
new Padding(
padding: const EdgeInsets.all(15.0),
child: new Text('Hot Products'),
),
Container(
height: 320.0,
child: Products(),
)
// Recent Products Ends here
],
),
);
}
}
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:shared_preferences/shared_preferences.dart';
import 'package:google_sign_in/google_sign_in.dart';
import 'package:fluttertoast/fluttertoast.dart';
class Login extends StatefulWidget {
@override
_LoginState createState() => _LoginState();
}
class _LoginState extends State<Login> {
final GoogleSignIn googleSignIn = new GoogleSignIn();
final FirebaseAuth firebaseAuth = FirebaseAuth.instance;
final FirebaseAuth _auth = FirebaseAuth.instance;
FirebaseAuth auth = FirebaseAuth.instance;
SharedPreferences preferences;
bool loading = false;
bool isLoggedin = false;
@override
void initState() {
// TODO: implement initState
super.initState();
isSignedIn();
}
void isSignedIn() async{
setState(() {
loading = true;
});
preferences = await SharedPreferences.getInstance();
isLoggedin = await googleSignIn.isSignedIn();
if(isLoggedin){
Navigator.pushReplacement(context, MaterialPageRoute(builder: (context) => HomePage()));
}
setState(() {
loading = false;
});
}
Future handleSignIn() async{
preferences = await SharedPreferences.getInstance();
setState(() {
loading = true;
});
GoogleSignInAccount googleUser = await googleSignIn.signIn();
GoogleSignInAuthentication googleSignInAuthentication = await googleUser.authentication;
/*FirebaseUser firebaseUser = await firebaseAuth.signInWithGoogle(
idToken: googleSignInAuthentication.idToken,
accessToken: googleSignInAuthentication.accessToken);*/
final AuthCredential credential = GoogleAuthProvider.getCredential(
accessToken: googleSignInAuthentication.accessToken,
idToken: googleSignInAuthentication.idToken,
);
final FirebaseUser firebaseUser = (await _auth.signInWithCredential(credential)).user;
if(firebaseUser != null){
final QuerySnapshot result = await Firestore.instance.collection("users").where("id",isEqualTo: firebaseUser.uid).getDocuments();
final List<DocumentSnapshot> documents =result.documents;
if(documents.length == 0){
// Insert the new user to our collection if the user is not found
Firestore.instance.collection("users").document(firebaseUser.uid).setData({
"id":firebaseUser.uid,
"username":firebaseUser.displayName,
"profilePicture":firebaseUser.photoUrl
});
await preferences.setString("id",firebaseUser.uid);
await preferences.setString("username",firebaseUser.displayName);
await preferences.setString("photoUrl",firebaseUser.photoUrl);
// Navigator.pushReplacement(context, MaterialPageRoute(builder: (context) => HomePage()));
}else{
await preferences.setString("id",documents[0]['id']);
await preferences.setString("username", documents[0]['username']);
await preferences.setString("photoUrl",documents[0]['photoUrl']);
}
Fluttertoast.showToast(msg: "Log In Success");
setState(() {
loading = false;
});
}else{
}
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: new AppBar(
elevation: 0.0,
backgroundColor: Colors.red,
title: Text('Login'),
actions: <Widget>[
new IconButton(
icon: Icon(
Icons.search,color: Colors.white),
onPressed: (){
}),
],
),
body: new Stack(
children: <Widget>[
Center(
child: FlatButton(
color: Colors.red,
onPressed: (){
handleSignIn();
},child: Text("Sign In / Sign Up with Google",style: TextStyle(color: Colors.white70),)),
),
Visibility(
visible: loading ?? true,
child: Center(
child: Container(
alignment: Alignment.center,
color: Colors.white.withOpacity(0.7),
child: CircularProgressIndicator(
valueColor: AlwaysStoppedAnimation<Color>(Colors.red),
),
),
),
)
],
),
);
}
}
import 'package:flutter/material.dart';
import 'package:my_kart_flash_app/screens/myCartProducts.dart';
class MyCart extends StatefulWidget {
@override
_MyCartState createState() => _MyCartState();
}
class _MyCartState extends State<MyCart> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: new AppBar(
elevation: 0.0,
backgroundColor: Colors.red,
title: Text('MyCart'),
actions: <Widget>[
new IconButton(
icon: Icon(
Icons.search,color: Colors.white),
onPressed: (){
}),
],
),
body: My_Cart_Products(),
bottomNavigationBar: new Container(
color: Colors.white,
child: Row(
children: <Widget>[
Expanded(child: ListTile(
title: new Text("Total Amount"),
subtitle: new Text("\$350"),
)),
Expanded(
child: new MaterialButton(onPressed: (){},
child: new Text("Check out", style: TextStyle(color: Colors.white),),
color: Colors.red
)
)
],
),
),
);
}
}
import 'package:flutter/material.dart';
class My_Cart_Products extends StatefulWidget {
@override
_My_Cart_ProductsState createState() => _My_Cart_ProductsState();
}
class _My_Cart_ProductsState extends State<My_Cart_Products> {
var Products_on_the_cart =[
{
"name": "Men Shirt and Dhothi",
"picture": "images/products/Men's_shirt_dhothi.JPG",
"sale_price": 550,
"size":"32",
"color":"Black",
"quantity":"1"
},
{
"name":"Baby Boy Western Wear",
"picture":"images/products/baby_boy_western_wear.JPG",
"sale_price":700,
"size":"S",
"color":"Blue",
"quantity":"1"
},
];