of static method

Returns the data most closely associated with the given context.

Note that if allowThrowingUnsafeAncestorException is set to true, a warning message will be printed and fallbackThemeData will be returned if "Looking up a deactivated widget's ancestor is unsafe" exception is thrown.

Implementation

static CustomPageRouteThemeData? of(BuildContext context) {
  try {
    final result = context.dependOnInheritedWidgetOfExactType<CustomPageRouteTheme>();
    return result?.data;
  } catch (e) {
    if (e.toString().contains("Looking up a deactivated widget's ancestor is unsafe") && !allowThrowingUnsafeAncestorException) {
      print('########## WARNING: FOLLOWING EXCEPTION IS THROWN WHEN CALLING CustomPageRouteTheme.of ##########');
      print(e);
      return fallbackThemeData; // defaults to null
    }
    rethrow;
  }
}