of static method

Translator of([
  1. BuildContext? context
])

Finds the Translator that was added to the widget tree via Provider. If no Translator is found on the widget tree then this will return a default, empty, instance.

Implementation

static Translator of([BuildContext? context]) {
  Translator? result;
  if (context != null) {
    try {
      result = Provider.of<Translator>(
        context,
        listen: false,
      );
    } catch (e) {
      // ignore and use a default instance
    }
  }

  return result ??
      Translator(
        language: 'default',
        loaders: {},
      );
}