popTill<T> function

void popTill<T>(
  1. BuildContext context,
  2. int count, {
  3. T? result,
})

A Dart function that pops the current route off the navigation stack a specified number of times.

Parameters:

  • context: the BuildContext associated with the current widget tree.
  • count: an integer value representing the number of times to pop the current route off the navigation stack.
  • result: an optional generic value representing the result to be returned to the previous route.

Returns: This function returns void, as it simply pops the current route off the navigation stack a specified number of times.

Example usage:

popTill<String>(context, 3, result: "Hello World!");

Pops the current route off the navigation stack 3 times and returns a String result.

Implementation

void popTill<T>(BuildContext context, int count, {T? result}) {
  for (int i = 1; i <= count; i++) {
    Navigator.of(context).pop<T>(result);
  }
}