From c4b05837b747411c1afb6c33e016bcc69d4676e8 Mon Sep 17 00:00:00 2001 From: pranavsrikanth <72306130+pranavsrikanth@users.noreply.github.com> Date: Fri, 30 Jul 2021 13:00:04 +0530 Subject: [PATCH 1/3] login fix --- lib/pages/signin_page.dart | 38 +++-- lib/pages/verification.dart | 304 ++++++++++++++++++------------------ 2 files changed, 173 insertions(+), 169 deletions(-) diff --git a/lib/pages/signin_page.dart b/lib/pages/signin_page.dart index 0a94347..7cb6d20 100644 --- a/lib/pages/signin_page.dart +++ b/lib/pages/signin_page.dart @@ -135,17 +135,19 @@ class _LoginPageState extends State { if (documentSnapshot.exists) { check = documentSnapshot.get("choice"); } else { - check = '0'; + check = '(0)'; } }); - if (check == "(1)") { + if (check == "(3)" || + check == "(2)" || + check == "(0)") { + FirebaseAuth.instance.signOut(); + print("No account found"); + } else { Navigator.push( context, MaterialPageRoute( builder: (context) => Donor())); - } else { - FirebaseAuth.instance.signOut(); - print("No account found"); } } else if (choice == "(2)") { FirebaseFirestore.instance @@ -156,17 +158,19 @@ class _LoginPageState extends State { if (documentSnapshot.exists) { check = documentSnapshot.get("choice"); } else { - check = '0'; + check = '(0)'; } }); - if (check == "(2)") { + if (check == "(3)" || + check == "(1)" || + check == "(0)") { + FirebaseAuth.instance.signOut(); + print("No account found"); + } else { Navigator.push( context, MaterialPageRoute( - builder: (context) => Shelter_page ())); - } else { - FirebaseAuth.instance.signOut(); - print("No account found"); + builder: (context) => Shelter_page())); } } else if (choice == "(3)") { FirebaseFirestore.instance @@ -177,17 +181,19 @@ class _LoginPageState extends State { if (documentSnapshot.exists) { check = documentSnapshot.get("choice"); } else { - check = '0'; + check = '(0)'; } }); - if (check == "(3)") { + if (check == "(2)" || + check == "(1)" || + check == "(0)") { + FirebaseAuth.instance.signOut(); + print("No account found"); + } else { Navigator.push( context, MaterialPageRoute( builder: (context) => Volunteer())); - } else { - FirebaseAuth.instance.signOut(); - print("No account found"); } } } on FirebaseAuthException catch (e) { diff --git a/lib/pages/verification.dart b/lib/pages/verification.dart index 621535b..0a25eee 100644 --- a/lib/pages/verification.dart +++ b/lib/pages/verification.dart @@ -22,22 +22,21 @@ class VerifcationPage extends StatefulWidget { } class _VerifcationPageState extends State { - int radio1; int radio2; int radio3; - int i =0 ; + int i = 0; int x = 0; - + @override void initState() { // TODO: implement initState super.initState(); radio1 = 0; radio2 = 0; - radio3=0; - i =0 ; - + radio3 = 0; + i = 0; + qrscan(); } // setRadio(value) { @@ -48,11 +47,8 @@ class _VerifcationPageState extends State { @override Widget build(BuildContext context) { - CollectionReference a = FirebaseFirestore.instance.collection('Shelter'); CollectionReference b = FirebaseFirestore.instance.collection('Owners'); - - if(x==0){qrscan();} doc = qr_code.substring(0, 20); uid = qr_code.substring(20, qr_code.length); @@ -83,8 +79,8 @@ class _VerifcationPageState extends State { // if(i<3) button = TextButton(onPressed: (){}, child: Text('Reject')); // if(i>=3) button = TextButton(onPressed: (){}, child: Text('Accept')); - TextButton(onPressed: (){}, child: Text('Accept')); - double width =MediaQuery.of(context).size.width; + TextButton(onPressed: () {}, child: Text('Accept')); + double width = MediaQuery.of(context).size.width; return Scaffold( appBar: AppBar( @@ -93,181 +89,183 @@ class _VerifcationPageState extends State { centerTitle: true, ), body: SingleChildScrollView( - child: Column( - children: [ - Row(mainAxisAlignment: MainAxisAlignment.spaceEvenly, children: [ - Text( - 'Name', - style: TextStyle(fontSize: 15), - ), - Text( - name, - style: TextStyle(fontSize: 15), - ), - ]), - Row(mainAxisAlignment: MainAxisAlignment.spaceEvenly, children: [ - Text( - 'Type', - style: TextStyle(fontSize: 15), - ), - Text( - type, - style: TextStyle(fontSize: 15), - ), - ]), - Row(mainAxisAlignment: MainAxisAlignment.spaceEvenly, children: [ - Text( - 'Quantity', - style: TextStyle(fontSize: 15), - ), - Text( - quantity, - style: TextStyle(fontSize: 15), - ), - ]), - Row(mainAxisAlignment: MainAxisAlignment.spaceEvenly, children: [ - Text( - 'Baby Product', - style: TextStyle(fontSize: 15), - ), - Text( - babyproduct, - style: TextStyle(fontSize: 15), - ), - ]), + child: Column(children: [ + Row(mainAxisAlignment: MainAxisAlignment.spaceEvenly, children: [ + Text( + 'Name', + style: TextStyle(fontSize: 15), + ), + Text( + name, + style: TextStyle(fontSize: 15), + ), + ]), + Row(mainAxisAlignment: MainAxisAlignment.spaceEvenly, children: [ + Text( + 'Type', + style: TextStyle(fontSize: 15), + ), + Text( + type, + style: TextStyle(fontSize: 15), + ), + ]), + Row(mainAxisAlignment: MainAxisAlignment.spaceEvenly, children: [ + Text( + 'Quantity', + style: TextStyle(fontSize: 15), + ), + Text( + quantity, + style: TextStyle(fontSize: 15), + ), + ]), + Row(mainAxisAlignment: MainAxisAlignment.spaceEvenly, children: [ + Text( + 'Baby Product', + style: TextStyle(fontSize: 15), + ), + Text( + babyproduct, + style: TextStyle(fontSize: 15), + ), + ]), - SizedBox(height:20), + SizedBox(height: 20), - Row(children: [ - Container(child: Wrap(children: [Text('Are the products sealed?')]),width: width*0.6), + Row( + children: [ + Container( + child: Wrap(children: [Text('Are the products sealed?')]), + width: width * 0.6), Radio( value: 1, groupValue: radio1, onChanged: (value) { - setState(() { - radio1 = value; + setState(() { + radio1 = value; - i++; - }); - - } - ) - - ],), - SizedBox(height:20), + i++; + }); + }) + ], + ), + SizedBox(height: 20), - Row(children: [ - Container(child: Wrap(children: [Text('Do the products have atleast 2 weeks before expiry')]),width: width*0.6), + Row( + children: [ + Container( + child: Wrap(children: [ + Text('Do the products have atleast 2 weeks before expiry') + ]), + width: width * 0.6), Radio( value: 2, groupValue: radio2, onChanged: (value) { setState(() { radio2 = value; - i++; + i++; }); - - - } - ) - ],), - SizedBox(height:20), - + }) + ], + ), + SizedBox(height: 20), - Row(children: [ - Container(child: Wrap(children: [Text('Do the products match the description above')]),width: width*0.6), + Row( + children: [ + Container( + child: Wrap(children: [ + Text('Do the products match the description above') + ]), + width: width * 0.6), Radio( value: 3, groupValue: radio3, onChanged: (value) { - setState(() { - radio3 = value; - i++; - }); - - } - ) - ],), - SizedBox(height:20), - - Row(children: [ - TextButton(onPressed: (){ a.doc('donations').collection('donations').doc(doc).set({ - 'Name': name, - 'Type': type, - 'Quantity': quantity, - 'Baby': babyproduct, - 'Status': 'Verified', - }); - b.doc(uid).collection('verified items').doc(doc).set({ - 'Name': name, - 'Type': type, - 'Quantity': quantity, - 'Baby': babyproduct, - 'Status': 'Verified', - }); - - b.doc(uid).collection('items').doc(doc).delete(); - Navigator.push(context, - MaterialPageRoute(builder: (context) => Volunteer())); - - }, child: Text('Accept')), - TextButton(onPressed: (){ - b.doc(uid).collection('items').doc(doc).delete(); - Navigator.push(context, - MaterialPageRoute(builder: (context) => Volunteer())); - }, child: Text('Reject')) - ],) + setState(() { + radio3 = value; + i++; + }); + }) + ], + ), + SizedBox(height: 20), + Row( + children: [ + TextButton( + onPressed: () { + a.doc('donations').collection('donations').doc(doc).set({ + 'Name': name, + 'Type': type, + 'Quantity': quantity, + 'Baby': babyproduct, + 'Status': 'Verified', + }); + b.doc(uid).collection('verified items').doc(doc).set({ + 'Name': name, + 'Type': type, + 'Quantity': quantity, + 'Baby': babyproduct, + 'Status': 'Verified', + }); - - - // Text('Do the products have more than 2 weeks of time before expiry?'), - // Text('Does the product match the description?') - - // ]), - // ), - // Column(children: [ - // Radio( - // value: 1, - // groupValue: 0, - // onChanged: (value) { - // setRadio(); - // i++; - // }), - // Radio( - // value: 1, - // groupValue: 0, - // onChanged: (value) { - // setRadio(); - // i++; - // }), - // Radio( - // value: 1, - // groupValue: 0, - // onChanged: (value) { - // setRadio(); - // i++; - // }) - // ],) - // ]), - + b.doc(uid).collection('items').doc(doc).delete(); + Navigator.push(context, + MaterialPageRoute(builder: (context) => Volunteer())); + }, + child: Text('Accept')), + TextButton( + onPressed: () { + b.doc(uid).collection('items').doc(doc).delete(); + Navigator.push(context, + MaterialPageRoute(builder: (context) => Volunteer())); + }, + child: Text('Reject')) + ], + ) - + // Text('Do the products have more than 2 weeks of time before expiry?'), + // Text('Does the product match the description?') - - ]), + // ]), + // ), + // Column(children: [ + // Radio( + // value: 1, + // groupValue: 0, + // onChanged: (value) { + // setRadio(); + // i++; + // }), + // Radio( + // value: 1, + // groupValue: 0, + // onChanged: (value) { + // setRadio(); + // i++; + // }), + // Radio( + // value: 1, + // groupValue: 0, + // onChanged: (value) { + // setRadio(); + // i++; + // }) + // ],) + // ]), + ]), ), ); - } - } Future qrscan() async { try { qr_code = await FlutterBarcodeScanner.scanBarcode( '#ff6666', 'Cancel', true, ScanMode.QR); - x=1; + x = 1; } on PlatformException { qr_code = 'Error'; } From dfd9559f16333501f3df989204978cbf6bb5d740 Mon Sep 17 00:00:00 2001 From: pranavsrikanth <72306130+pranavsrikanth@users.noreply.github.com> Date: Fri, 30 Jul 2021 16:24:52 +0530 Subject: [PATCH 2/3] qr barely works --- lib/pages/donor_dashboard.dart | 22 ++++++++++--------- lib/pages/verification.dart | 40 +++++++++++++++++++--------------- 2 files changed, 34 insertions(+), 28 deletions(-) diff --git a/lib/pages/donor_dashboard.dart b/lib/pages/donor_dashboard.dart index 6dfd7b4..038182e 100644 --- a/lib/pages/donor_dashboard.dart +++ b/lib/pages/donor_dashboard.dart @@ -19,6 +19,7 @@ class Donor extends StatefulWidget { class _DonorState extends State { @override Widget build(BuildContext context) { + print(uidDonor); return Scaffold( appBar: AppBar( title: Text("Dashboard"), @@ -37,14 +38,13 @@ class _DonorState extends State { leading: Icon(Icons.map_outlined), ), ListTile( - title: Text('Logout'), - leading: Icon(Icons.logout), - onTap: (){ FirebaseAuth.instance.signOut(); - Navigator.push( - context, - MaterialPageRoute( - builder: (context) => SplashScreen()));} - ) + title: Text('Logout'), + leading: Icon(Icons.logout), + onTap: () { + FirebaseAuth.instance.signOut(); + Navigator.push(context, + MaterialPageRoute(builder: (context) => SplashScreen())); + }) ], ), ), @@ -109,8 +109,10 @@ class _DonorState extends State { TextButton( child: const Text('View'), onPressed: () { - Navigator.push(context, - MaterialPageRoute(builder: (context) => Verified())); + Navigator.push( + context, + MaterialPageRoute( + builder: (context) => Verified())); }, ), const SizedBox(width: 8), diff --git a/lib/pages/verification.dart b/lib/pages/verification.dart index 0a25eee..b03eae2 100644 --- a/lib/pages/verification.dart +++ b/lib/pages/verification.dart @@ -7,11 +7,9 @@ import 'package:flutterlogindesign/pages/qr.dart'; import 'package:flutterlogindesign/pages/qrscan.dart'; import 'package:flutterlogindesign/pages/volunteer_page.dart'; -String qr_code = ''; String doc; String uid; - -int x = 0; +String qr_code; var name, type, quantity, babyproduct; class VerifcationPage extends StatefulWidget { @@ -26,7 +24,6 @@ class _VerifcationPageState extends State { int radio2; int radio3; int i = 0; - int x = 0; @override void initState() { @@ -36,6 +33,10 @@ class _VerifcationPageState extends State { radio2 = 0; radio3 = 0; i = 0; + name = ""; + type = ""; + quantity = ""; + babyproduct = ""; qrscan(); } @@ -51,7 +52,7 @@ class _VerifcationPageState extends State { CollectionReference b = FirebaseFirestore.instance.collection('Owners'); doc = qr_code.substring(0, 20); - uid = qr_code.substring(20, qr_code.length); + uid = qr_code.substring(20); // for(int i=0;i<20;i++) // { @@ -62,16 +63,20 @@ class _VerifcationPageState extends State { // uid = ''+qrcode[i]; // } - final info = FirebaseFirestore.instance + var info = FirebaseFirestore.instance .collection('Owners') .doc(uid) .collection('items') .doc(doc); info.get().then((DocumentSnapshot documentSnapshot) { - name = documentSnapshot.get('Name'); - type = documentSnapshot.get('Type'); - quantity = documentSnapshot.get('Quantity'); - babyproduct = documentSnapshot.get('Baby'); + if (documentSnapshot.exists) { + name = documentSnapshot.get('Name').toString(); + type = documentSnapshot.get('Type').toString(); + quantity = documentSnapshot.get('Quantity').toString(); + babyproduct = documentSnapshot.get('Baby').toString(); + } else + CircularProgressIndicator(); + print("here"); }); print(qr_code); @@ -259,14 +264,13 @@ class _VerifcationPageState extends State { ), ); } -} -Future qrscan() async { - try { - qr_code = await FlutterBarcodeScanner.scanBarcode( - '#ff6666', 'Cancel', true, ScanMode.QR); - x = 1; - } on PlatformException { - qr_code = 'Error'; + Future qrscan() async { + try { + qr_code = await FlutterBarcodeScanner.scanBarcode( + '#ff6666', 'Cancel', true, ScanMode.QR); + } on PlatformException { + qr_code = 'Error'; + } } } From 23440c316dcb4e887e4b97c255c50982b1260991 Mon Sep 17 00:00:00 2001 From: Bhavya L Narayanan Date: Fri, 30 Jul 2021 16:58:26 +0530 Subject: [PATCH 3/3] Toast --- lib/pages/item_page.dart | 11 +++++++++ lib/pages/signin_page.dart | 50 +++++++++++++++++++++++++++++++++++++- lib/pages/signup_page.dart | 32 +++++++++++++++++++++++- pubspec.lock | 7 ++++++ pubspec.yaml | 1 + 5 files changed, 99 insertions(+), 2 deletions(-) diff --git a/lib/pages/item_page.dart b/lib/pages/item_page.dart index 6f6f6b3..3eb17c6 100644 --- a/lib/pages/item_page.dart +++ b/lib/pages/item_page.dart @@ -5,6 +5,7 @@ import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:flutterlogindesign/pages/donor_dashboard.dart'; import 'package:flutterlogindesign/pages/qr.dart'; +import 'package:fluttertoast/fluttertoast.dart'; String generatedID; @@ -95,6 +96,16 @@ class _State extends State { generatedID = querySnapshot.id.toString() + uidDonor.toString(); // Here we call the ID of the document + Fluttertoast.showToast( + msg: "Item added.", + toastLength: Toast.LENGTH_LONG, + gravity: ToastGravity.BOTTOM, + timeInSecForIosWeb: 1, + backgroundColor: Colors.red, + textColor: Colors.white, + fontSize: 16.0 + ); + }); diff --git a/lib/pages/signin_page.dart b/lib/pages/signin_page.dart index 7cb6d20..fab40c7 100644 --- a/lib/pages/signin_page.dart +++ b/lib/pages/signin_page.dart @@ -8,6 +8,7 @@ import 'package:flutterlogindesign/widgets/btn_widget.dart'; import 'package:flutterlogindesign/widgets/Headdersignup.dart'; import 'package:firebase_auth/firebase_auth.dart'; import 'package:cloud_firestore/cloud_firestore.dart'; +import 'package:fluttertoast/fluttertoast.dart'; import 'donor_dashboard.dart'; @@ -142,6 +143,15 @@ class _LoginPageState extends State { check == "(2)" || check == "(0)") { FirebaseAuth.instance.signOut(); + Fluttertoast.showToast( + msg: "No account found", + toastLength: Toast.LENGTH_LONG, + gravity: ToastGravity.BOTTOM, + timeInSecForIosWeb: 1, + backgroundColor: Colors.red, + textColor: Colors.white, + fontSize: 16.0 + ); print("No account found"); } else { Navigator.push( @@ -165,6 +175,15 @@ class _LoginPageState extends State { check == "(1)" || check == "(0)") { FirebaseAuth.instance.signOut(); + Fluttertoast.showToast( + msg: "No account found", + toastLength: Toast.LENGTH_LONG, + gravity: ToastGravity.BOTTOM, + timeInSecForIosWeb: 1, + backgroundColor: Colors.red, + textColor: Colors.white, + fontSize: 16.0 + ); print("No account found"); } else { Navigator.push( @@ -188,6 +207,15 @@ class _LoginPageState extends State { check == "(1)" || check == "(0)") { FirebaseAuth.instance.signOut(); + Fluttertoast.showToast( + msg: "No account found", + toastLength: Toast.LENGTH_LONG, + gravity: ToastGravity.BOTTOM, + timeInSecForIosWeb: 1, + backgroundColor: Colors.red, + textColor: Colors.white, + fontSize: 16.0 + ); print("No account found"); } else { Navigator.push( @@ -198,8 +226,26 @@ class _LoginPageState extends State { } } on FirebaseAuthException catch (e) { if (e.code == 'user-not-found') { + Fluttertoast.showToast( + msg: "No user found for that email.", + toastLength: Toast.LENGTH_LONG, + gravity: ToastGravity.BOTTOM, + timeInSecForIosWeb: 1, + backgroundColor: Colors.red, + textColor: Colors.white, + fontSize: 16.0 + ); print('No user found for that email.'); } else if (e.code == 'wrong-password') { + Fluttertoast.showToast( + msg: "Wrong password provided for that user.", + toastLength: Toast.LENGTH_LONG, + gravity: ToastGravity.BOTTOM, + timeInSecForIosWeb: 1, + backgroundColor: Colors.red, + textColor: Colors.white, + fontSize: 16.0 + ); print('Wrong password provided for that user.'); } } @@ -231,6 +277,7 @@ class _LoginPageState extends State { color: Colors.black54, decoration: TextDecoration.underline, )), + ]), ) ], @@ -240,9 +287,10 @@ class _LoginPageState extends State { ), ), ), + ); } - + Widget _textInput({hint, icon, myController, obscure}) { return Container( margin: EdgeInsets.only(top: 10), diff --git a/lib/pages/signup_page.dart b/lib/pages/signup_page.dart index 3df8967..9da2f8f 100644 --- a/lib/pages/signup_page.dart +++ b/lib/pages/signup_page.dart @@ -7,6 +7,7 @@ import 'package:flutterlogindesign/pages/volunteer_page.dart'; import 'package:flutterlogindesign/widgets/btn_widget.dart'; import 'package:flutterlogindesign/widgets/Headdersignup.dart'; import 'package:firebase_auth/firebase_auth.dart'; +import 'package:fluttertoast/fluttertoast.dart'; import 'donor_dashboard.dart'; @@ -127,12 +128,41 @@ class _RegPageState extends State { } } on FirebaseAuthException catch (e) { if (e.code == 'weak-password') { + Fluttertoast.showToast( + msg: "The password provided is too weak.", + toastLength: Toast.LENGTH_LONG, + gravity: ToastGravity.BOTTOM, + timeInSecForIosWeb: 1, + backgroundColor: Colors.red, + textColor: Colors.white, + fontSize: 16.0 + ); print('The password provided is too weak.'); - } else if (e.code == 'email-already-in-use') { + } else if (e.code == 'email-already-in-use') { + Fluttertoast.showToast( + msg: "The account already exists for that email.", + toastLength: Toast.LENGTH_LONG, + gravity: ToastGravity.BOTTOM, + timeInSecForIosWeb: 1, + backgroundColor: Colors.red, + textColor: Colors.white, + fontSize: 16.0 + ); + print( 'The account already exists for that email.'); } } catch (e) { + Fluttertoast.showToast( + msg: "$e", + toastLength: Toast.LENGTH_LONG, + gravity: ToastGravity.BOTTOM, + timeInSecForIosWeb: 1, + backgroundColor: Colors.red, + textColor: Colors.white, + fontSize: 16.0 + ); + print(e); } }, diff --git a/pubspec.lock b/pubspec.lock index 249d759..08f9a16 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -198,6 +198,13 @@ packages: description: flutter source: sdk version: "0.0.0" + fluttertoast: + dependency: "direct main" + description: + name: fluttertoast + url: "https://pub.dartlang.org" + source: hosted + version: "8.0.7" http_parser: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index 4e101de..f094d55 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -26,6 +26,7 @@ dependencies: flutter: sdk: flutter firebase_core: "0.7.0" + fluttertoast: ^8.0.7