InjectedI18NImp<I18N> constructor

InjectedI18NImp<I18N>({
  1. required Map<Locale, FutureOr<I18N> Function()> i18Ns,
  2. String? persistKey,
  3. required StateInterceptor<I18N>? stateInterceptor,
  4. required SideEffects<I18N>? sideEffects,
  5. DependsOn<I18N>? dependsOn,
  6. int undoStackLength = 0,
  7. bool autoDisposeWhenNotUsed = true,
  8. String? debugPrintWhenNotifiedPreMessage,
  9. required Object? toDebugString(
    1. I18N?
    )?,
})

Implementation

InjectedI18NImp({
  required this.i18Ns,
  String? persistKey,
  //
  required StateInterceptor<I18N>? stateInterceptor,
  required SideEffects<I18N>? sideEffects,
  //
  DependsOn<I18N>? dependsOn,
  int undoStackLength = 0,
  //
  bool autoDisposeWhenNotUsed = true,
  String? debugPrintWhenNotifiedPreMessage,
  required Object? Function(I18N?)? toDebugString,
}) {
  final persist = persistKey == null
      ? null
      : PersistState<I18N>(
          key: persistKey,
          fromJson: (json) {
            final s = json.split('#|#');
            assert(s.length <= 3);
            if (s.first.isEmpty) {
              return _getLanguage(SystemLocale());
            }
            final l = Locale.fromSubtags(
              languageCode: s.first,
              scriptCode: s.length > 2 ? s[1] : null,
              countryCode: s.last.isNotEmpty ? s.last : null,
            );

            return _getLanguage(l);
          },
          toJson: (key) {
            String l = '';
            if (_locale is SystemLocale) {
              l = '#|#';
            } else {
              l = '${_locale!.languageCode}#|#' +
                  (_locale?.scriptCode != null
                      ? '${_locale!.scriptCode}#|#'
                      : '') +
                  '${_locale!.countryCode}';
            }
            return l;
          },
        );
  injected = Injected<I18N>.generic(
    creator: () => _getLanguage(SystemLocale()),
    initialState: null,
    sideEffects: SideEffects<I18N>(
      initState: sideEffects?.initState,
      dispose: () {
        sideEffects?.dispose?.call();
        dispose();
      },
      onAfterBuild: sideEffects?.onAfterBuild,
      onSetState: sideEffects?.onSetState != null
          ? (snap) {
              //For InjectedI18N and InjectedTheme schedule side effects
              //for the next frame.
              WidgetsBinding.instance.addPostFrameCallback(
                (_) => sideEffects!.onSetState!(snap),
              );
            }
          : null,
    ),
    stateInterceptor: stateInterceptor,
    persist: persist != null ? () => persist : null,
    undoStackLength: undoStackLength,
    dependsOn: dependsOn,
    autoDisposeWhenNotUsed: autoDisposeWhenNotUsed,
    debugPrintWhenNotifiedPreMessage: debugPrintWhenNotifiedPreMessage,
    toDebugString: toDebugString,
  ) as InjectedImp<I18N>;
  _resetDefaultState = () {
    _locale = null;
  };
  _resetDefaultState();
}