onChange static method

void onChange(
  1. dynamic callback(
    1. Map<String, String>
    ), {
  2. bool? immediate = false,
  3. bool? runOnce = false,
})

Listen to changes in the query string.

The callback function will be called whenever the query string changes.

The immediate parameter is used to determine if the callback should be called immediately.

The runOnce parameter is used to determine if the callback should be called only once.

Implementation

static void onChange(
  Function(Map<String, String>) callback, {
  bool? immediate = false,
  bool? runOnce = false,
}) {
  _controller.stream.listen((data) {
    if (immediate!) {
      callback(data);
    } else {
      // delay the callback to allow the query string to be updated
      Future.delayed(Duration(milliseconds: 100), () {
        callback(data);
      });
    }

    if (runOnce!) {
      _controller.close();
    }

    callback(data);
  });
}