I am writing a flutter app, where I am using the flutter I18n package. It works fine on the most placed, but when I try to use it in a method, which creates an other widget, it crashes with the following error.
The following NoSuchMethodError was thrown building LightLocationWidget(dirty, dependencies: [_LocalizationsScope-[GlobalKey#ced6b]], state: _LightLocationWidgetState#3b5b6): The getter 'decodedMap' was called on null. Receiver: null Tried calling: decodedMap When the exception was thrown, this was the stack: Object.noSuchMethod (dart:core-patch/object_patch.dart:51:5) FlutterI18n._translateWithKeyFallback (package:flutter_i18n/flutter_i18n.dart:162:43) FlutterI18n.translate (package:flutter_i18n/flutter_i18n.dart:139:26)
In the package its this method:
static String _translateWithKeyFallback(
final BuildContext context, final String key) {
final Map<String, dynamic> decodedStrings =
_retrieveCurrentInstance(context).decodedMap;
String translation = _decodeFromMap(decodedStrings, key);
if (translation == null) {
print("**$key** not found");
translation = key;
}
return translation;}
My code which throws the exception:
@override
Widget build(BuildContext context) {
return Row(
children: [
Padding(
padding: EdgeInsets.all(10),
child: getLightButton(1),
)
...
ButtonTheme getLightButton(int typeNumber) {
return ButtonTheme(
child: FlatButton(
child: Column(children: [Text(FlutterI18n.translate(context, "lightlocation")
...
When I use this key directly on the widget it works without problems.