Flutter升级:更新最新版本的Flutter之前的功能不起作用

时间:2018-09-25 12:49:49

标签: dart flutter flutter-layout

我已经在v0.5.1的flutter版本中尝试了此功能,并且工作正常,没有问题。更新到最新版本v0.8.4后,出现以下异常。

  

ExcceptionDatainheritFromWidgetOfExactType(_LocalizationsScope)原为   在ProfileScreen.initState()完成之前调用。

        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 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.

  @override
  void initState() {
    super.initState();
    makeRequest();
  }
  Future<DataModel> makeRequest() async {
    _onLoading();

    http.Response response = await http.get(Uri.encodeFull(getProfile),
        headers: {"Accept": "application/json"});

   /// json data calling.....
  }

  void _onLoading() {

    if (loadCheck) {
        showDialog(
            context: context,
            barrierDismissible: false,
            builder: (BuildContext context) {
              return new Dialog(
                // progress dialog calling );
            }
        );
    } else {
      Navigator.pop(context);
    }
  }

1 个答案:

答案 0 :(得分:-1)

您需要来自的上下文

WHILE

在Widget构建后粘贴方法...,然后像这样将参数(上下文)传递到括号中

@override Widget build(BuildContext context) {
....
....
makeRequest() 

再次

makeRequest(context) 

并使用

_onLoading(context) 

如果使用Provider和InitState,这是一个常见问题。

相关问题