flutter_i18n
flutter_i18n copied to clipboard
Plugin always starts with english locale
Hi. I created new project to test flutter_i18n (version 0.32.3) and later implement it to other project. My code is very close to example. I used NetworkFileTranslationLoader, all with it works correct except one thing: application always starts with english language, doesn't matter what language set in system. If i trace variables on app start, ui.window.locale outputs correct device locale, but FlutterI18n.currentLocale(context) shows 'en_US' and plugin loads english translation by default. Tryed on Android emulator and real device.
Here are parts of code:
void main() async {
final FlutterI18nDelegate flutterI18nDelegate = FlutterI18nDelegate(
translationLoader: NetworkFileTranslationLoader(
useCountryCode: true,
fallbackFile: 'en_US',
baseUri: Uri.https("mysite.com", "strings"),
),
);
WidgetsFlutterBinding.ensureInitialized();
runApp(MyApp(flutterI18nDelegate));
}
class MyApp extends StatelessWidget {
final FlutterI18nDelegate flutterI18nDelegate;
MyApp(this.flutterI18nDelegate);
@override
Widget build(BuildContext context) {
...
class AboutScreen extends StatefulWidget {
const AboutScreen({Key key}) : super(key: key);
@override
_AboutScreenState createState() => new _AboutScreenState();
}
class _AboutScreenState extends State<AboutScreen> {
Locale currentLang;
@override
void initState() {
super.initState();
//currentLang = ui.window.locale;
Future.delayed(Duration.zero, () async {
setState(() {
currentLang = FlutterI18n.currentLocale(context);
});
});
}
@override
Widget build(BuildContext context) {
...
If more info needed, i will provide.