triggerNavigationEvent function

Future<void> triggerNavigationEvent({
  1. required BuildContext context,
  2. required String route,
  3. String? event,
  4. bool shouldReplace = false,
  5. Object? args,
  6. bool shouldRemoveUntil = false,
})

Triggers Navigation event by sending a log to firebase

@params

  • String route (determines the route to push to after sending log)
  • bool shouldReplace (is used as a flag for navigation events that replace previous routes)
  • BuildContext context

Implementation

Future<void> triggerNavigationEvent({
  required BuildContext context,
  required String route,
  String? event,
  bool shouldReplace = false,
  Object? args,
  bool shouldRemoveUntil = false,
}) async {
  /// Navigation Function
  if (shouldReplace) {
    triggerEvent(navigationEvent, context, route: route);
    await Navigator.of(context).pushReplacementNamed(route, arguments: args);
  } else if (shouldRemoveUntil) {
    triggerEvent(navigationEvent, context, route: route);
    await Navigator.of(context).pushNamedAndRemoveUntil(
      route,
      ModalRoute.withName(route),
      arguments: args,
    );
  } else {
    triggerEvent(navigationEvent, context, route: route);
    await Navigator.of(context).pushNamed(route, arguments: args);
  }
}