areNavigationStackEquals method

  1. @visibleForTesting
bool areNavigationStackEquals(
  1. Iterable<Destination> leftStack,
  2. Iterable<Destination> rightStack
)

Check the equality between two list of destination.

leftStack to be verified. rightStack to be verified.

return true if both stack are equals.

Note: equals only in path not arguments or histories.

Implementation

@visibleForTesting
bool areNavigationStackEquals(
  final Iterable<Destination> leftStack,
  final Iterable<Destination> rightStack,
) {
  // if the stack don't have the same length they are definitely not equal.
  if (leftStack.length != rightStack.length) {
    return false;
  }

  final List<String> leftStackPaths =
      leftStack.map((Destination destination) => destination.path).toList();

  final List<String> rightStackPaths =
      rightStack.map((Destination destination) => destination.path).toList();

  for (int index = 0; index < leftStackPaths.length; index++) {
    final String leftPath = leftStackPaths[index];
    final String rightPath = rightStackPaths[index];

    if (leftPath != rightPath) {
      return false;
    }
  }

  return true;
}