Skip to content

Commit

Permalink
added image upload option
Browse files Browse the repository at this point in the history
  • Loading branch information
pm020202pm committed Jul 16, 2023
1 parent 5b0671a commit 5428444
Show file tree
Hide file tree
Showing 9 changed files with 300 additions and 166 deletions.
41 changes: 16 additions & 25 deletions lib/accepted_tab.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,6 @@ class _AcceptedTabState extends State<AcceptedTab> {
acceptUsers();
}

Future<void> _refreshAcceptedUsers() async {
await Future.delayed(
const Duration(seconds: 1));
acceptUsers();
}

Future<void> acceptUsers () async {
QuerySnapshot querySnapshot = await FirebaseFirestore.instance.collection('Users').get();
Expand Down Expand Up @@ -59,26 +54,22 @@ class _AcceptedTabState extends State<AcceptedTab> {

@override
Widget build(BuildContext context) {
return RefreshIndicator(
onRefresh: _refreshAcceptedUsers,
child: FutureBuilder<List<QueryDocumentSnapshot>>(
future: fetchFirestoreDocuments(),
builder: (BuildContext context,
AsyncSnapshot<List<QueryDocumentSnapshot>> snapshot) {
if (snapshot.connectionState == ConnectionState.waiting) { return const Text("Loading..."); }
if (snapshot.hasError) {return Text('Error: ${snapshot.error}');}
List<QueryDocumentSnapshot> documents = snapshot.data!;

return ListView.builder(
itemCount: documents.length,
itemBuilder: (BuildContext context, int index) {
var name = documents[index].get('Name');
var time = documents[index].get('Time');
return UserCard(color: Colors.green, name: name, time: time, isMatched: true);
},
);
},
)
return FutureBuilder<List<QueryDocumentSnapshot>>(
future: fetchFirestoreDocuments(),
builder: (BuildContext context,
AsyncSnapshot<List<QueryDocumentSnapshot>> snapshot) {
if (snapshot.connectionState == ConnectionState.waiting) { return const Text("Loading..."); }
if (snapshot.hasError) {return Text('Error: ${snapshot.error}');}
List<QueryDocumentSnapshot> documents = snapshot.data!;
return ListView.builder(
itemCount: documents.length,
itemBuilder: (BuildContext context, int index) {
var name = documents[index].get('Name');
var time = documents[index].get('Time');
return UserCard(color: Colors.green, name: name, time: time, isMatched: true, imageUrl: 'assets/avatar.png',);
},
);
},
);
}
}
10 changes: 4 additions & 6 deletions lib/catalogue_tab.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,9 @@ class _CatalogueTabState extends State<CatalogueTab> {
children: [
const Padding(
padding: EdgeInsets.fromLTRB(10, 5, 0, 0),
child: Text('My Request', style: TextStyle(), textAlign: TextAlign.left,),
),
Container(
child: MyCard(),
child: Text('My Request'),
),
MyCard(),
],
),
const SizedBox(height: 20,),
Expand All @@ -43,14 +41,14 @@ class _CatalogueTabState extends State<CatalogueTab> {
if (snapshot.connectionState == ConnectionState.waiting) { return const Text('Loading...'); }
if (snapshot.hasError) {return Text('Error: ${snapshot.error}');}
List<QueryDocumentSnapshot> documents = snapshot.data!;

return ListView.builder(
itemCount: documents.length,
itemBuilder: (BuildContext context, int index) {
var name = documents[index].get('Name');
var time = documents[index].get('Time');
var isMatched = documents[index].get('isMatched');
return UserCard(color: isMatched? Colors.green : null, name: name, time: time, isMatched: false);
var imageUrl = documents[index].get('imageUrl');
return UserCard(color: isMatched? Colors.green : null, name: name, time: time, isMatched: false, imageUrl: imageUrl,);
},
);
},
Expand Down
19 changes: 9 additions & 10 deletions lib/constants.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@ import 'package:cloud_firestore/cloud_firestore.dart';

late String userUid;
bool myList=false;

/////CHECK FOR MULTIPLE REQUEST FROM SINGLE USER
Future<bool> duplicates() async {
QuerySnapshot querySnapshot = await FirebaseFirestore.instance
.collection('Users')
.where("Uid", isEqualTo: userUid)
.get();
QuerySnapshot querySnapshot = await FirebaseFirestore.instance.collection('Users').where("Uid", isEqualTo: userUid).get();
if (querySnapshot.docs.isNotEmpty) {
return true;
}
Expand All @@ -15,20 +14,20 @@ Future<bool> duplicates() async {
}
}

////RETRIEVING DATA OF DOCUMENT EXCEPT USER's DOCUMENT
Future<List<QueryDocumentSnapshot>> fetchFirestoreDocuments() async {
QuerySnapshot querySnapshot = await FirebaseFirestore.instance.collection('Users').get();
// Access the documents in the query snapshot
final querySnapshot = await FirebaseFirestore.instance.collection('Users').where('Uid', isNotEqualTo: userUid).get();
List<QueryDocumentSnapshot> documents = querySnapshot.docs;
return documents;
}


void deleteContact(String documentId) {
FirebaseFirestore.instance.collection('Users').doc(documentId).delete()
.then((value) {
FirebaseFirestore.instance.collection('Users').doc(documentId).delete().then((value) {
print('Contact deleted successfully.');
})
.catchError((error) {
}).catchError((error) {
print('Failed to delete contact: $error');
});
}


17 changes: 6 additions & 11 deletions lib/login_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class _LoginPageState extends State<LoginPage> {
final TextEditingController emailController = TextEditingController();
final TextEditingController passwordController = TextEditingController();

/////REGISTER WITH EMAIL AND PASSWORD
void registerWithEmailAndPassword(String email, String password) async {
try {
UserCredential userCredential = await FirebaseAuth.instance.createUserWithEmailAndPassword(
Expand All @@ -25,6 +26,7 @@ class _LoginPageState extends State<LoginPage> {
}
}

/////SIGN IN WITH EMAIL AND PASSWORD
void signInWithEmailAndPassword(String email, String password) async {
try {
UserCredential userCredential = await FirebaseAuth.instance.signInWithEmailAndPassword(
Expand All @@ -41,9 +43,8 @@ class _LoginPageState extends State<LoginPage> {
myList=true;
});
}
print('YOUR LIST BOOL : $myList');
print('MY LIST BOOL : $myList');
Navigator.push(context, MaterialPageRoute(builder: (context)=> MyHomePage()));

}
}
catch (e) {
Expand All @@ -59,21 +60,15 @@ class _LoginPageState extends State<LoginPage> {
child: Center(
child: Column(
children: [
TextField(
controller: emailController,
),
TextField(controller: emailController,),
const SizedBox(height: 30,),
TextField(
controller: passwordController,
),
TextField(controller: passwordController,),
TextButton(
onPressed: (){registerWithEmailAndPassword(emailController.text, passwordController.text);},
child: const Text('Register')
),
TextButton(
onPressed: (){
signInWithEmailAndPassword(emailController.text, passwordController.text);
},
onPressed: (){signInWithEmailAndPassword(emailController.text, passwordController.text);},
child: const Text('Login')
),
],
Expand Down
2 changes: 1 addition & 1 deletion lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class MyApp extends StatelessWidget {
Widget build(BuildContext context) {
return MaterialApp(
routes:{
'/homepage' : (context) => MyHomePage(),
'/homepage' : (context) => const MyHomePage(),
},
title: 'TravelDost',
theme: ThemeData(
Expand Down
Loading

0 comments on commit 5428444

Please sign in to comment.