popMatching method

void popMatching(
  1. String value, {
  2. bool exactMatch = false,
})

Go back in history and grab the first route that does not match the provided route. Used in this demo to close all of the details pages you might have in your history stack

Implementation

void popMatching(String value, {bool exactMatch = false}) {
  int index = history.lastIndexWhere((element) => exactMatch ? element != value : element.contains(value) == false);
  List<String> newHistory = List.from(history)..removeRange(index + 1, history.length);
  path = newHistory.last;
  //TODO: Is it an issue that routeChanged handlers will fire before history stack is finalized? Would it be better to have something like ignoreNext?
  history = newHistory;
}