In my profile page I have a form with some components. Some of these components are dropdown that helps selecting a value (e.g. Countries).
As the app is multi language I am using the following process to have strings saved always with the same value but translated on their labels.
Added some json files in the Assets section of the app. For example for genres i have multiple files like the following:
//English
[
{ "label": "Male", "code": "Male" },
{ "label": "Female", "code": "Female" },
{ "label": "I'd rather not say.", "code": "Undeclared" }
]
//Espanol
[
{ "label": "Masculino", "code": "Male" },
{ "label": "Femenina", "code": "Female" },
{ "label": "PreferirΓa no decirlo", "code": "Undeclared" }
]
These files are named as (for the previous example)
genres_en.json
,genres_es.json
and so onWhen the app is loaded I am able to get current language with the Internationalization function and load all the lookups for the language of the app. All the values are the set into an app state variable which contains a list of custom data type. This works perfectly.
When a page need to show a dropdown I am setting up three properties:
Define option values. Here I put the following path
AppState Variable -> Map List Items -> Item in List -> Data Structure Field -> code
Define option labels. Here I put the following path
AppState Variable -> Map List Items -> Item in List -> Data Structure Field -> label
Initial Option Value. This is the value coming from database storage or api call (called on page load) and is set, for example, from a custom data type (e.g.
participant -> gender
This all worked smoothly until now that I have upgraded to FF 6.0.5 mac app.
Now whenever I get into a page with a dropdown I get the following error:
β
βββ‘ EXCEPTION CAUGHT BY WIDGETS LIBRARY ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
The following assertion was thrown building Builder:
dependOnInheritedWidgetOfExactType<_LocalizationsScope>() or dependOnInheritedElement() was called before
_ProfileDetailB1WidgetState.initState() completed. When an inherited widget changes, for example if the value of
Theme.of() changes, its dependent widgets are rebuilt. If the dependent widget's
reference to the inherited widget is in a constructor or an initState() method, then the
rebuilt dependent widget will not reflect the changes in the inherited widget. Typically
references to inherited widgets should occur in widget build() methods. Alternatively,
initialization based on inherited widgets can be placed in the didChangeDependencies
method, which is called after initState and whenever the dependencies change thereafter.
The relevant error-causing widget was:
Navigator-[LabeledGlobalKey<NavigatorState>#06aed]
Navigator:file:///Users/xxxxxx/.pub-cache/hosted/pub.dev/go_router-12.1.3/lib/src/builder.dart:316:30
When the exception was thrown, this was the stack:
#0 StatefulElement.dependOnInheritedElement.<anonymous closure> (package:flutter/src/widgets/framework.dart:5864:9)
#1 StatefulElement.dependOnInheritedElement (package:flutter/src/widgets/framework.dart:5907:6)
#2 Element.dependOnInheritedWidgetOfExactType (package:flutter/src/widgets/framework.dart:4922:14)
#3 Localizations.of (package:flutter/src/widgets/localizations.dart:536:48)
#4 FFLocalizations.of (package:fidelity/flutter_flow/internationalization.dart:14:21)
#5 _ProfileDetailB1WidgetState.initState (package:fidelity/pages/profile/business/profile_detail_b1/profile_detail_b1_widget.dart:68:29)
Any suggestion?