build method
Implementation
@override
FutureOr<ActivityRepository> build() {
final repository = ActivityRepository();
final stream =
ref.read(firestoreServiceProvider).activityStream().asBroadcastStream();
// Wait for the first event. This contains all the activities from this
// month onward.
return stream.first.then((dynamicActivitiesSnapshot) {
// After the first event, listen to events. These events are changes to
// activities.
_subscription =
stream.listen((querySnapshot) => _parseQuerySnapShot(querySnapshot));
// Parse all the activities and add them to the repository.
final dynamicActivities = dynamicActivitiesSnapshot.docChanges
.map((doc) => doc.doc.data()!)
.toList();
// Check if the local notification should be updated
_checkIfLocalNotificationShouldBeUpdated(dynamicActivities);
// Start fetching the static activities from the MyAEGEE API.
// This is done in the background, so the user can already see the
// activities from the Firestore database.
_getStaticActivities().then((staticActivities) {
update((repository) {
return updateRepoWithNewActivities(
repository,
staticActivities,
);
});
});
// Return the respository
return updateRepoWithNewActivities(
repository,
dynamicActivities,
);
});
}