Getting BuildContext in Flutter for localization

后端 未结 4 1902
名媛妹妹
名媛妹妹 2021-02-13 17:00

I try to localize a String in Flutter with the localization package. The problem is the location where my translation is needed. It is not related to the UI, rather it is somewh

4条回答
  •  庸人自扰
    2021-02-13 17:33

    No, there is no other way because it is stored using an InheritedWidget, which is a part of the build tree and thus can only be accessed with a reference to it (the BuildContext).
    You will need to pass your context to somewhere deep in your model.

提交回复
热议问题