invokeCallback<T> method

  1. @protected
T invokeCallback <T>(String name, RecognizerCallback<T> callback, { String debugReport() })
@protected

Invoke a callback provided by the application, catching and logging any exceptions.

The name argument is ignored except when reporting exceptions.

The debugReport argument is optional and is used when debugPrintRecognizerCallbacksTrace is true. If specified, it must be a callback that returns a string describing useful debugging information, e.g. the arguments passed to the callback.

Implementation

@protected
T invokeCallback<T>(String name, RecognizerCallback<T> callback, { String debugReport() }) {
  assert(callback != null);
  T result;
  try {
    assert(() {
      if (debugPrintRecognizerCallbacksTrace) {
        final String report = debugReport != null ? debugReport() : null;
        // The 19 in the line below is the width of the prefix used by
        // _debugLogDiagnostic in arena.dart.
        final String prefix = debugPrintGestureArenaDiagnostics ? ' ' * 19 + '❙ ' : '';
        debugPrint('$prefix$this calling $name callback.${ report?.isNotEmpty == true ? " $report" : "" }');
      }
      return true;
    }());
    result = callback();
  } catch (exception, stack) {
    FlutterError.reportError(FlutterErrorDetails(
      exception: exception,
      stack: stack,
      library: 'gesture',
      context: 'while handling a gesture',
      informationCollector: (StringBuffer information) {
        information.writeln('Handler: $name');
        information.writeln('Recognizer:');
        information.writeln('  $this');
      }
    ));
  }
  return result;
}