LocalizationProvider constructor

LocalizationProvider({
  1. Key? key,
  2. required Widget child,
  3. required List<String> initialTranslations,
  4. bool debugMode = false,
  5. required Locale initialLocale,
  6. required List<SupportedTranslation> supportedTranslations,
  7. bool saveLocale = false,
})

Constructs a LocalizationProvider that exposes localizationManager to its descendants.

key Identifies this widget in the widget tree. child The widget below this widget in the tree that can access the provided localizationManager. localizationManager The single instance of LocalizationManager to be provided to all dependent widgets.

Implementation

LocalizationProvider(
    {Key? key,
    required Widget child,
    required this.initialTranslations,
    this.debugMode = false,
    required this.initialLocale,
    required this.supportedTranslations,
    this.saveLocale = false})
    : super(
          key: key ?? instanceKey,
          child: debugMode ? ReassembleListener(child: child) : child) {
  List<Locale> locales = supportedTranslations[0].paths.keys.toList();
  for (Locale locale in locales) {
    List<Translation> translations = [];
    for (SupportedTranslation tr in supportedTranslations) {
      translations
          .add(Translation(name: tr.name, path: tr.paths[locale].toString()));
    }
    SupportedLocale supLocale =
        SupportedLocale(locale: locale, translations: translations);
    supportedLocales.add(supLocale);
  }
  _localizationManager = LocalizationManager(
    supportedLocales: supportedLocales,
    initialLocale: initialLocale,
    initialTranslations: initialTranslations,
    debugMode: debugMode,
  );
}