replaceGestureRecognizers method

void replaceGestureRecognizers (Map<Type, GestureRecognizerFactory<GestureRecognizer>> gestures)

This method can be called after the build phase, during the layout of the nearest descendant RenderObjectWidget of the gesture detector, to update the list of active gesture recognizers.

The typical use case is Scrollables, which put their viewport in their gesture detector, and then need to know the dimensions of the viewport and the viewport's child to determine whether the gesture detector should be enabled.

The argument should follow the same conventions as RawGestureDetector.gestures. It acts like a temporary replacement for that value until the next build.

Implementation

void replaceGestureRecognizers(Map<Type, GestureRecognizerFactory> gestures) {
  assert(() {
    if (!context.findRenderObject().owner.debugDoingLayout) {
      throw FlutterError(
        'Unexpected call to replaceGestureRecognizers() method of RawGestureDetectorState.\n'
        'The replaceGestureRecognizers() method can only be called during the layout phase. '
        'To set the gesture recognizers at other times, trigger a new build using setState() '
        'and provide the new gesture recognizers as constructor arguments to the corresponding '
        'RawGestureDetector or GestureDetector object.'
      );
    }
    return true;
  }());
  _syncAll(gestures);
  if (!widget.excludeFromSemantics) {
    final RenderSemanticsGestureHandler semanticsGestureHandler = context.findRenderObject();
    _updateSemanticsForRenderObject(semanticsGestureHandler);
  }
}