Skip to content

Commit

Permalink
firebase integration completed
Browse files Browse the repository at this point in the history
following featured have been covered:
- create event
- register in event
- create and get notes for events
- check no of registrations
- see dairy page, events in which you are registered
- save contact from a hand written document to your phone just in one click
- Alhamdulilah for every thing
  • Loading branch information
mtalhahabib committed Dec 31, 2023
1 parent 58bb8e5 commit 0beafb3
Show file tree
Hide file tree
Showing 23 changed files with 1,225 additions and 671 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Generated file.
//
// If you wish to remove Flutter's multidex support, delete this entire file.
//
// Modifications to this file should be done in a copy under a different name
// as this file may be regenerated.

package io.flutter.app;

import android.app.Application;
import android.content.Context;
import androidx.annotation.CallSuper;
import androidx.multidex.MultiDex;

/**
* Extension of {@link android.app.Application}, adding multidex support.
*/
public class FlutterMultiDexApplication extends Application {
@Override
@CallSuper
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
MultiDex.install(this);
}
}
7 changes: 4 additions & 3 deletions lib/controllers/signUpController.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'package:firebase_auth/firebase_auth.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:web_project/database/registrationDatabase.dart';
import 'package:web_project/fitness_app/fitness_app_home_screen.dart';

class SignUpController extends GetxController {
Expand All @@ -10,15 +11,15 @@ class SignUpController extends GetxController {
TextEditingController().obs;
final Rx<TextEditingController> confirmPasswordController =
TextEditingController().obs;
createUserWithEmailAndPassword(context, email, password) async {
createUserWithEmailAndPassword(context, email, password, name) async {
try {

final credential =
await FirebaseAuth.instance.createUserWithEmailAndPassword(
email: email,
password: password,
);

final uid = credential.user!.uid;
RegistrationDatabase().setUserName(uid, email, name);
Navigator.push(
context,
MaterialPageRoute(
Expand Down
71 changes: 71 additions & 0 deletions lib/database/createEventDatabase.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import 'dart:io';

import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:firebase_storage/firebase_storage.dart';
import 'package:get/get.dart';

class Create {
final database = FirebaseFirestore.instance;
final FirebaseStorage storage = FirebaseStorage.instance;
Future<void> createEvent(String uid, String title, String imagePath,
String date, String time, String location, String notes) async {
DocumentReference eventdocs = database
.collection('users')
.doc('events')
.collection('eventsCollection')
.doc();
String eventId=eventdocs.id;
eventdocs.set({
'eventId':eventId,
'OrganizerID': uid,
'title': title,
'imagePath': imagePath,
'date': date,
'time': time,
'location': location,
'notes': notes,
'registrations': []
}).then((value) async {});
}

Future<String> uploadImageAndGetUrl(imagePath) async {
if (imagePath != null) {
File file = File(imagePath);

// Upload image to Firebase Storage
String fileName = DateTime.now().millisecondsSinceEpoch.toString();
Reference storageReference = storage.ref().child('images/$fileName.jpg');
UploadTask uploadTask = storageReference.putFile(file);
await uploadTask.whenComplete(() => null);

// Get download URL
String imageUrl = await storageReference.getDownloadURL();

// Save image URL in Firestore

print('Image uploaded and URL saved: $imageUrl');
return imageUrl;
} else {
print('No image selected.');
return '';
}
}

Future<void> someOneRegistered(String eventId, String name) async {
try{
DocumentReference eventdocs = database
.collection('users')
.doc('events')
.collection('eventsCollection')
.doc(eventId);
eventdocs.update({

'registrations':FieldValue.arrayUnion([name]),
}).then((value) async {});
}
catch(e){
Get.snackbar('Error', e.toString());
}
}

}
45 changes: 45 additions & 0 deletions lib/database/registrationDatabase.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:get/get.dart';

class RegistrationDatabase {
final database = FirebaseFirestore.instance;

Future<void> setUserName(
String uid,
String email,
String name,
) async {
await database.collection('users').doc(uid).set({
'name': name,
'email': email,
'eventID': [],
}).then((value) async {
Get.snackbar('Congrat', 'You have been Registered');
});
}

Future<String> getUserName(
String uid,
) async {
DocumentSnapshot snapshot =
await FirebaseFirestore.instance.collection('users').doc(uid).get();

final name = snapshot.data() as Map<String, dynamic>;
return name['name'].toString();
}

Future<void> registerInEvent(String uid, String eventID) async {
try{
await database.collection('users').doc(uid).update({
'eventID': FieldValue.arrayUnion([eventID]),
}).then((value) async {
Get.snackbar('Congratulations', 'You have been Registered in this Event');
});
}
catch(e){
Get.snackbar('Error', '${e.toString()}');
}
}


}
41 changes: 41 additions & 0 deletions lib/database/retrieveEventData.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import 'dart:io';

import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:firebase_storage/firebase_storage.dart';

class RetrieveEvents {
Stream<QuerySnapshot> retrieveEventData() {
final database = FirebaseFirestore.instance;
Stream<QuerySnapshot> events = database
.collection('users')
.doc('events')
.collection('eventsCollection')
.snapshots();
return events;
}

Future<List<String>> Idees(uid) async {
final database = FirebaseFirestore.instance;
final snapshot = await database.collection('users').doc(uid).get();
List<String> Idees = snapshot.data()?['eventID'];
return Idees;
}

retrieveMyEvents(uid) async {
final database = FirebaseFirestore.instance;

final snapshot = await database.collection('users').doc(uid).get();
final eventMap = snapshot.data() as Map<String, dynamic>;

final Ids = eventMap['eventID'];

final events = database
.collection('users')
.doc('events')
.collection('eventsCollection')
.where(FieldPath.documentId, whereIn: Ids)
.get();
return events;
}

}
76 changes: 48 additions & 28 deletions lib/design_course/category_list_view.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:firebase_auth/firebase_auth.dart';
import 'package:flutter/material.dart';
import 'package:hexcolor/hexcolor.dart';
import 'package:web_project/database/retrieveEventData.dart';
import 'package:web_project/design_course/course_info_screen.dart';
import 'package:web_project/design_course/design_course_app_theme.dart';
import 'package:web_project/design_course/models/category.dart';
Expand All @@ -24,10 +27,6 @@ class _CategoryListViewState extends State<CategoryListView>
super.initState();
}

Future<bool> getData() async {
await Future<dynamic>.delayed(const Duration(milliseconds: 50));
return true;
}

@override
void dispose() {
Expand All @@ -42,37 +41,53 @@ class _CategoryListViewState extends State<CategoryListView>
child: Container(
height: 150,
width: double.infinity,
child: FutureBuilder<bool>(
future: getData(),
builder: (BuildContext context, AsyncSnapshot<bool> snapshot) {
child: StreamBuilder<QuerySnapshot>(
stream: RetrieveEvents().retrieveEventData(),
builder: (BuildContext context, AsyncSnapshot<QuerySnapshot> snapshot) {
if (!snapshot.hasData) {
return const SizedBox();
} else {
return Center(child: Text('No Data to Display'),);
}
else if(snapshot.hasError) {
return Center(child: Text('Error: ${snapshot.error}'),);
}
else if(snapshot.connectionState == ConnectionState.waiting) {
return Center(child: CircularProgressIndicator(color: Colors.brown,),);
}

else if(snapshot.hasData) {

final eventList = snapshot.data!.docs;


return ListView.builder(
padding: const EdgeInsets.only(
top: 0, bottom: 0, right: 16, left: 16),
itemCount: Category.categoryList.length,
itemCount: eventList.length,
scrollDirection: Axis.horizontal,
itemBuilder: (BuildContext context, int index) {
final int count = Category.categoryList.length > 10
final int count = eventList.length > 10
? 10
: Category.categoryList.length;
: eventList.length;
final Animation<double> animation =
Tween<double>(begin: 0.0, end: 1.0).animate(
CurvedAnimation(
parent: animationController!,
curve: Interval((1 / count) * index, 1.0,
curve: Curves.fastOutSlowIn)));
animationController?.forward();

final eventMap =
eventList[index].data() as Map<String, dynamic>;
return CategoryView(
category: Category.categoryList[index],
eventMap: eventMap,
animation: animation,
animationController: animationController,
);
},
);
}
else {
return Center(child: Text('------------'),);
}
},
),
),
Expand All @@ -81,16 +96,17 @@ class _CategoryListViewState extends State<CategoryListView>
}

class CategoryView extends StatelessWidget {
const CategoryView({
CategoryView({
Key? key,
this.category,
required this.eventMap,
this.animationController,
this.animation,
}) : super(key: key);
final Category? category;
final Map<String,dynamic> eventMap;
final AnimationController? animationController;
final Animation<double>? animation;

String userId = FirebaseAuth.instance.currentUser!.uid;
@override
Widget build(BuildContext context) {
return AnimatedBuilder(
Expand All @@ -108,12 +124,14 @@ class CategoryView extends StatelessWidget {
context,
MaterialPageRoute<dynamic>(
builder: (BuildContext context) => CourseInfoScreen(
image: category!.imagePath,
title: category!.title,
date: category!.date,
time: category!.time,
location: category!.location,
money: category!.money,
image: eventMap['imagePath'],
title: eventMap['title'],
date: eventMap['date'],
time: eventMap['time'],
location: eventMap['location'],
eventId: eventMap['eventId'],
uid: userId,
money: 0,
),
),
);
Expand Down Expand Up @@ -148,7 +166,7 @@ class CategoryView extends StatelessWidget {
padding:
const EdgeInsets.only(top: 16),
child: Text(
category!.title,
eventMap['title'],
textAlign: TextAlign.left,
style: TextStyle(
fontWeight: FontWeight.w600,
Expand All @@ -173,7 +191,8 @@ class CategoryView extends StatelessWidget {
CrossAxisAlignment.center,
children: <Widget>[
Text(
'${category!.date} ',
eventMap['date'],

textAlign: TextAlign.left,
style: TextStyle(
fontWeight: FontWeight.w200,
Expand All @@ -187,7 +206,8 @@ class CategoryView extends StatelessWidget {
child: Row(
children: <Widget>[
Text(
'${category!.time}',

eventMap['time'],
textAlign:
TextAlign.left,
style: TextStyle(
Expand Down Expand Up @@ -221,7 +241,7 @@ class CategoryView extends StatelessWidget {
CrossAxisAlignment.start,
children: <Widget>[
Text(
'Rs${category!.money}',
'Rs${0}',
textAlign: TextAlign.left,
style: TextStyle(
fontWeight: FontWeight.w600,
Expand Down Expand Up @@ -277,7 +297,7 @@ class CategoryView extends StatelessWidget {
const BorderRadius.all(Radius.circular(16.0)),
child: AspectRatio(
aspectRatio: 1.0,
child: Image.asset(category!.imagePath)),
child: Image.network(eventMap['imagePath'])),
)
],
),
Expand Down
Loading

0 comments on commit 0beafb3

Please sign in to comment.