getEvents method
Future<void> getEvents ()
This function is used to fetch all the events of an organization.
params: None
returns:
Future<void>
: void
Implementation
Future<void> getEvents() async {
// refresh user's access token
await _dbFunctions.refreshAccessToken(userConfig.currentUser.refreshToken!);
_dbFunctions.init();
// get current organization id
final String currentOrgID = _currentOrg.id!;
// mutation to fetch the events
final String mutation = EventQueries().fetchOrgEvents(currentOrgID);
final result = await _dbFunctions.gqlAuthMutation(mutation);
if (result == null) return;
final List eventsJson = result.data!["eventsByOrganization"] as List;
eventsJson.forEach((eventJsonData) {
final Event event = Event.fromJson(eventJsonData as Map<String, dynamic>);
event.isRegistered = event.registrants?.any(
(registrant) => registrant.id == _userConfig.currentUser.id,
) ??
false;
_eventStreamController.add(event);
});
}