createDispatcher<T> static method

SlidableGroupNotificationDispatcher<T>? createDispatcher<T>(
  1. BuildContext context, {
  2. bool assertParentExists = true,
})

Creates a dispatcher used to dispatch the notification to the closest SlidableGroupBehavior with the given type.

assertParentExists is only used internally to not throws an assertion error if there are no SlidableGroupBehaviors in the tree.

It can be useful to call this method instead of dispatch in case you want to send a last notification before disposing a StatefulWidget.

Implementation

static SlidableGroupNotificationDispatcher<T>? createDispatcher<T>(
  BuildContext context, {
  bool assertParentExists = true,
}) {
  final widget = context
      .getElementForInheritedWidgetOfExactType<
          _InheritedSlidableNotification<T>>()
      ?.widget as _InheritedSlidableNotification<T>?;

  assert(() {
    if (assertParentExists && widget == null) {
      throw FlutterError(
        'SlidableGroupBehavior.of<$T> called with a context that '
        'does not contain a SlidableGroupBehavior<$T>.',
      );
    }
    return true;
  }());
  if (widget != null) {
    return SlidableGroupNotificationDispatcher<T>._(widget);
  }

  return null;
}