mirror of
https://github.com/inventree/inventree-app.git
synced 2025-04-28 05:26:47 +00:00
I18N fallback for null context
This commit is contained in:
parent
dce3b6c14a
commit
855a1481b2
17
lib/l10.dart
17
lib/l10.dart
@ -1,9 +1,22 @@
|
||||
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
|
||||
import 'package:one_context/one_context.dart';
|
||||
import 'package:flutter_gen/gen_l10n/app_localizations_en.dart';
|
||||
|
||||
import 'package:one_context/one_context.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
// Shortcut function to reduce boilerplate!
|
||||
I18N L10()
|
||||
{
|
||||
return I18N.of(OneContext().context)!;
|
||||
BuildContext? _ctx = OneContext().context;
|
||||
|
||||
if (_ctx != null) {
|
||||
I18N? i18n = I18N.of(_ctx);
|
||||
|
||||
if (i18n != null) {
|
||||
return i18n;
|
||||
}
|
||||
}
|
||||
|
||||
// Fallback for "null" context
|
||||
return I18NEn();
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user