maybeFindMessenger<T> static method

T? maybeFindMessenger<T>(
  1. BuildContext context
)

Find the DataMessenger that holds all of the data with the given type from the context.

  • T The type of the data.
  • context The build context.

Implementation

static T? maybeFindMessenger<T>(BuildContext context) {
  assert(context.mounted, 'The context must be mounted');
  InheritedDataHolderWidget? holder =
      context.findAncestorWidgetOfExactType<InheritedDataHolder<T>>();
  holder ??= context.findAncestorWidgetOfExactType<InheritedRootDataHolder>();
  if (holder != null) {
    return holder.holder.findData(context, T);
  }
  return null;
}