Flutter-翻译oninit

时间:2019-03-11 11:41:18

标签: flutter internationalization

1级

@override
      void initState() {
        super.initState();
        text =DemoLocalizations.of(context).trans('connection');
      }

第2类(DemoLocalizations)

 Future<bool> load() async {

    String data = await rootBundle.loadString('locale/i18n_${locale.languageCode}.json');
    Map<String, dynamic> _result = json.decode(data);

    this._sentences = new Map();
    _result.forEach((String key, dynamic value) {
      this._sentences[key] = value.toString();
    });

    return true;
  }

返回

enter image description here

问题是:屏幕加载(oninit)时如何加载自定义字符串(国际化)?

0 个答案:

没有答案