Reputation: 1669
Following the tips of the official internationalization tutorial I am getting the The getter was called on null
when trying to use the autogenerated from ARB files translation engine (AppLocalizations.of(context).helloWrold
):
import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
class Login extends StatelessWidget {
final loginAction;
final String loginError;
const Login(this.loginAction, this.loginError);
@override
Widget build(BuildContext context) {
return Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
RaisedButton(
onPressed: () {
loginAction();
},
child: Text(AppLocalizations.of(context).helloWorld),
),
Text(loginError ?? ''),
],
);
}
}
Upvotes: 0
Views: 746
Reputation: 1669
The solution to this problem is a missing part of the official tutorial. It is not described there that to allow the engine to function, one needs to declare additional delegate in the main.dart
file. This can be concluded out of the example GitHub repository. To fix the issue, go to the MaterialApp
and add the missing delegate AppLocalizations.delegate
:
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
child: MaterialApp(
localizationsDelegates: [
// ... app-specific localization delegate[s] here
AppLocalizations.delegate,
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
GlobalCupertinoLocalizations.delegate,
],
supportedLocales: [
const Locale('en', ''),
const Locale('pl', '')
],
home: Scaffold(
Upvotes: 8