of static method

GetRootState of(
  1. BuildContext context
)

Retrieves the state of the GetRoot widget from the given BuildContext.

This method is used to access the state of the GetRoot widget from any descendant widget's BuildContext.

If the BuildContext provided is not associated with a GetRoot widget, this method will throw a FlutterError.

Implementation

static GetRootState of(BuildContext context) {
  // Handles the case where the input context is a navigator element.
  GetRootState? root;
  if (context is StatefulElement && context.state is GetRootState) {
    root = context.state as GetRootState;
  }
  root = context.findRootAncestorStateOfType<GetRootState>() ?? root;
  assert(() {
    if (root == null) {
      throw FlutterError(
        'GetRoot operation requested with a context that does not include a GetRoot.\n'
        'The context used must be that of a '
        'widget that is a descendant of a GetRoot widget.',
      );
    }
    return true;
  }());
  return root!;
}