Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes MVP - Talawa #2108 #2114

Merged
merged 16 commits into from
Nov 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 40 additions & 25 deletions lib/services/navigation_service.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
// ignore_for_file: talawa_api_doc
// ignore_for_file: talawa_good_doc_comments

import 'package:flutter/material.dart';
import 'package:talawa/enums/enums.dart';
import 'package:talawa/widgets/talawa_error_dialog.dart';
Expand All @@ -21,50 +18,62 @@ import 'package:talawa/widgets/talawa_error_snackbar.dart';
class NavigationService {
GlobalKey<NavigatorState> navigatorKey = GlobalKey<NavigatorState>();

/// This function push the route to the navigator.
/// Pushes a Screen.
///
/// **params**:
/// * `routeName`: Name of the Route
/// * `arguments`: Set of arguments
///
/// params:
/// * [routeName]
/// * [arguments] : necessary data for the route
/// **returns**:
/// * `Future<dynamic>`: resolves if the Screen was succesfully pushed.
Future<dynamic> pushScreen(String routeName, {dynamic arguments}) {
return navigatorKey.currentState!
.pushNamed(routeName, arguments: arguments);
}

/// This function pop the initial route and push the new route to the navigator.
///
/// params:
/// * [routeName]
/// * [arguments] : necessary data for the route
/// **params**:
/// * `routeName`: Name of the Route
/// * `arguments`: Set of arguments
///
/// **returns**:
/// * `Future<dynamic>`: resolves if the Screen was succesfully popAndPushed.
Future<dynamic> popAndPushScreen(String routeName, {dynamic arguments}) {
navigatorKey.currentState!.pop();
return pushScreen(routeName, arguments: arguments);
}

/// This function push the route and replace the screen.
///
/// params:
/// * [routeName]
/// * [arguments] : necessary data for the route
/// **params**:
/// * `routeName`: Name of the Route
/// * `arguments`: Set of arguments
///
/// **returns**:
/// * `Future<dynamic>`: resolves if the Screen was succesfully pushedReplacementScreen.
Future<dynamic> pushReplacementScreen(String routeName, {dynamic arguments}) {
return navigatorKey.currentState!
.pushReplacementNamed(routeName, arguments: arguments);
}

void fromInviteLink(List<String> routeNames, List<dynamic> arguments) {
int i = 0;
removeAllAndPush('/${routeNames[i]}', '/', arguments: arguments[i]);
for (i = 1; i < routeNames.length; i++) {
pushScreen('/${routeNames[i]}', arguments: arguments[i]);
}
}
// void fromInviteLink(List<String> routeNames, List<dynamic> arguments) {
// int i = 0;
// removeAllAndPush('/${routeNames[i]}', '/', arguments: arguments[i]);
// for (i = 1; i < routeNames.length; i++) {
// pushScreen('/${routeNames[i]}', arguments: arguments[i]);
// }
// }

/// This function remove all the routes till the particular route and add new route.
///
/// params:
/// * [routeName] : route that need to add
/// * [tillRoute] : remove all route until this route.
/// * [arguments] : necessary data for the route
/// **params**:
/// * `routeName`: Name of the Route
/// * `tillRoute`: Route till we want to remove
/// * `arguments`: Set of arguments
///
/// **returns**:
/// * `Future<dynamic>`: resolves if the Screen was succesfully removeAllAndPushed.
Future<dynamic> removeAllAndPush(
String routeName,
String tillRoute, {
Expand All @@ -77,7 +86,13 @@ class NavigationService {
);
}

/// This function is used to show the custom Dialog.
/// This function remove all the routes till the particular route and add new route.
///
/// **params**:
/// * `dialog`: Widget to show
///
/// **returns**:
/// None
void pushDialog(Widget dialog) {
showDialog(
context: navigatorKey.currentContext!,
Expand Down
Loading
Loading