of static method

Gets the not-null AutoLocalization instance from given BuildContext. If not found throws an FlutterError

Implementation

static AutoLocalization of(BuildContext context) {
  final localizations = AutoLocalization.maybeOf(context);
  if (localizations == null) {
    throw FlutterError.fromParts([
      ErrorSummary('No AutoLocalization found.'),
      ErrorDescription(
          '${context.widget.runtimeType} widgets require AutoLocalization '
          'to be provided by a Localizations widget ancestor.'),
      ErrorHint(
          'Did you forget to add AutoLocalization localization delegate to '
          'MaterialApp widget?'),
      ...context.describeMissingAncestor(
        expectedAncestorType: AutoLocalization,
      )
    ]);
  }
  return localizations;
}