InjectedI18NImp<I18N> constructor
InjectedI18NImp<I18N> ({
- required Map<
Locale, FutureOr< i18Ns,I18N> Function()> - String? persistKey,
- required StateInterceptor<
I18N> ? stateInterceptor, - required SideEffects<
I18N> ? sideEffects, - DependsOn<
I18N> ? dependsOn, - int undoStackLength = 0,
- bool autoDisposeWhenNotUsed = true,
- String? debugPrintWhenNotifiedPreMessage,
- required Object? toDebugString(
- 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();
}