Skip to content

Commit

Permalink
implemented design
Browse files Browse the repository at this point in the history
  • Loading branch information
jomazao committed Feb 12, 2024
1 parent 6da3598 commit 6f32659
Show file tree
Hide file tree
Showing 18 changed files with 1,047 additions and 405 deletions.
248 changes: 248 additions & 0 deletions .idea/libraries/Dart_Packages.xml

Large diffs are not rendered by default.

23 changes: 18 additions & 5 deletions .idea/libraries/Flutter_Plugins.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file added assets/images/calendar.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/location.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 16 additions & 0 deletions functions/attendees-counter.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import * as functions from 'firebase-functions';
import * as admin from 'firebase-admin';

admin.initializeApp();

export const updateAttendeesCount = functions.firestore
.document('event/{eventId}/attendees/{attendeeId}')
.onWrite(async (change, context) => {
const eventId = context.params.eventId;
const eventRef = admin.firestore().collection('event').doc(eventId);

const attendeesSnapshot = await eventRef.collection('attendees').get();
const attendeesCount = attendeesSnapshot.size;

return eventRef.update({ attendees: attendeesCount });
});
2 changes: 2 additions & 0 deletions lib/src/config/app_assets.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
class AppAssets {
static const _imagesPath = 'assets/images';
static const banner = '$_imagesPath/banner.jpeg';
static const calendar = '$_imagesPath/calendar.png';
static const location = '$_imagesPath/location.png';
}
10 changes: 10 additions & 0 deletions lib/src/config/app_colors.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import 'package:flutter/painting.dart';

class AppColors {
static const iconBackground = Color(0x195669FF);
static const primary = Color(0xFF5669FF);
static const primaryFont = Color(0xFF3F38DD);
static const flutterNavy = Color(0xFF042B59);

static const cancel = Color(0xFF042B59);
}
80 changes: 50 additions & 30 deletions lib/src/config/router.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import 'package:flutter_community_ibague/src/models/event.dart';
import 'package:flutter_community_ibague/src/notifiers/auth_notifier.dart';
import 'package:flutter_community_ibague/src/notifiers/event_notifier.dart';
import 'package:flutter_community_ibague/src/notifiers/events_notifier.dart';
import 'package:flutter_community_ibague/src/ui/screens/event_detail_screen.dart';
import 'package:flutter_community_ibague/src/ui/screens/events_screen.dart';
import 'package:flutter_community_ibague/src/ui/screens/home_screen.dart';
import 'package:flutter_community_ibague/src/ui/screens/person_screen.dart';
Expand All @@ -10,43 +13,60 @@ class Routes {
static const person = '/person';
static const notLogged = '/not_logged';
static const events = '/events';
static const eventDetails = '/event-details';
}

final GoRouter appRouter = GoRouter(
initialLocation: Routes.events,
routes: <RouteBase>[
ShellRoute(
builder: (context, state, child) {
return MultiProvider(
providers: [
ChangeNotifierProvider(
create: (_) => EventsNotifier(),
),
ChangeNotifierProvider(
create: (_) => AuthNotifier(),
),
],
child: HomeScreen(
builder: (context, state, child) {
return MultiProvider(
providers: [
ChangeNotifierProvider(
create: (_) => EventsNotifier(),
),
ChangeNotifierProvider(
create: (_) => AuthNotifier(),
),
],
child: child,
);
},
routes: [
GoRoute(
name: Routes.eventDetails,
path: Routes.eventDetails,
builder: (context, state) {
final event = state.extra as Event;
return ChangeNotifierProvider(
create: (_) => EventNotifier(event: event),
child: const EventDetailScreen());
},
),
);
},
routes: [
GoRoute(
name: Routes.events,
path: Routes.events,
builder: (context, state) {
return const EventsScreen();
},
),
GoRoute(
name: Routes.person,
path: Routes.person,
builder: (context, state) {
return const PersonScreen();
},
),
],
),
ShellRoute(
builder: (context, state, child) {
return HomeScreen(
child: child,
);
},
routes: [
GoRoute(
name: Routes.events,
path: Routes.events,
builder: (context, state) {
return const EventsScreen();
},
),
GoRoute(
name: Routes.person,
path: Routes.person,
builder: (context, state) {
return const PersonScreen();
},
),
],
),
])
],
);
43 changes: 14 additions & 29 deletions lib/src/data/events_repository.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,41 +22,26 @@ class EventsRepository {
.toList());
}

Future<int> attendeesCount(String eventId) async {
final result = await _firestore
Stream<Event> eventStream({required String id}) {
return _firestore
.collection('events')
.doc(eventId)
.collection('attendees')
.count()
.get();
return result.count ?? 0;
.doc(id)
.snapshots()
.map((doc) => Event.fromJson(
id: doc.id,
json: doc.data() ?? {},
));
}

Future<void> attendToEvent(String eventId, String uid) async {
await _firestore
.collection('events')
.doc(eventId)
.collection('attendees')
.doc(uid)
.set({'attend': true});
await _firestore.collection('events').doc(eventId).update({
'attendees': FieldValue.arrayUnion([uid])
});
}

Future<void> notAttendToEvent(String eventId, String uid) async {
await _firestore
.collection('events')
.doc(eventId)
.collection('attendees')
.doc(uid)
.delete();
}

Stream<bool> attendStream(String eventId, String uid) {
return _firestore
.collection('events')
.doc(eventId)
.collection('attendees')
.doc(uid)
.snapshots()
.map((doc) => doc.exists);
await _firestore.collection('events').doc(eventId).update({
'attendees': FieldValue.arrayRemove([uid])
});
}
}
29 changes: 26 additions & 3 deletions lib/src/models/event.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,15 @@ class Event {
final String description;
final String banner;
final DateTime dateTime;
final String location;
final String locationTitle;
final String recommendations;
int attendees = 0;
final String locationDetails;
final GeoPoint location;
final String calendarUrl;
final String locationUrl;
final List<String> attendees;

int get attendeesCount => attendees.length;

Event({
required this.id,
Expand All @@ -18,6 +24,11 @@ class Event {
required this.dateTime,
required this.location,
required this.recommendations,
required this.locationDetails,
required this.locationTitle,
required this.calendarUrl,
required this.locationUrl,
required this.attendees,
});

factory Event.fromJson({
Expand All @@ -26,14 +37,26 @@ class Event {
}) {
final dateTimeTimeStamp = json['dateTime'] as Timestamp;

final recommendations =
(json['recommendations'] as String ?? '').replaceAll("\\n", "\n");

final attendees = (json['attendees'] as List<dynamic>? ?? [])
.map<String>((uid) => '$uid')
.toList();

return Event(
id: id,
title: json['title'] ?? '',
description: json['description'] ?? '',
banner: json['banner'] ?? '',
dateTime: dateTimeTimeStamp.toDate(),
location: json['location'] ?? '',
recommendations: json['recommendations'] ?? '',
locationTitle: json['location_title'] ?? '',
locationDetails: json['location_details'] ?? '',
locationUrl: json['location_url'] ?? '',
calendarUrl: json['calendar_url'] ?? '',
recommendations: recommendations,
attendees: attendees,
);
}
}
46 changes: 35 additions & 11 deletions lib/src/notifiers/event_notifier.dart
Original file line number Diff line number Diff line change
@@ -1,25 +1,49 @@
import 'dart:async';

import 'package:firebase_auth/firebase_auth.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter_community_ibague/src/data/events_repository.dart';
import 'package:flutter_community_ibague/src/models/event.dart';

class EventNotifier extends ChangeNotifier {
final EventsRepository _eventsRepository;
final FirebaseAuth _auth;

final String eventId;
Event event;
bool get attending => event.attendees.any((uid) => uid == _user?.uid);
late final StreamSubscription _eventSubscription;
User? get _user => _auth.currentUser;

EventNotifier({
required this.eventId,
required this.event,
EventsRepository? eventsRepository,
}) : _eventsRepository = eventsRepository ?? EventsRepository();
FirebaseAuth? auth,
}) : _eventsRepository = eventsRepository ?? EventsRepository(),
_auth = auth ?? FirebaseAuth.instance {
print('listen to event');
_eventSubscription =
_eventsRepository.eventStream(id: event.id).listen((event) {
print(event);
event = event;
notifyListeners();
});
}

void attendEvent() {
if (_user != null) {
_eventsRepository.attendToEvent(event.id, _user!.uid);
}
}

void attendEvent(
String uid,
) {
_eventsRepository.attendToEvent(eventId, uid);
void notAttendEvent() {
if (_user != null) {
_eventsRepository.notAttendToEvent(event.id, _user!.uid);
}
}

void notAttendEvent(
String uid,
) {
_eventsRepository.notAttendToEvent(eventId, uid);
@override
void dispose() {
_eventSubscription.cancel();
super.dispose();
}
}
9 changes: 6 additions & 3 deletions lib/src/notifiers/events_notifier.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,14 @@ class EventsNotifier extends ChangeNotifier {
void init() {
_eventsSubscription =
_eventsRepository.eventsStream().listen((events) async {
for (final event in events) {
event.attendees = await _eventsRepository.attendeesCount(event.id);
}
this.events = events;
notifyListeners();
});
}

@override
void dispose() {
_eventsSubscription.cancel();
super.dispose();
}
}
Loading

0 comments on commit 6f32659

Please sign in to comment.