gpt4 book ai didi

dart - Flutter升级:在更新最新版本的Flutter之后,先前的功能不起作用

转载 作者:行者123 更新时间:2023-12-03 04:08:44 27 4
gpt4 key购买 nike

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

ExcceptionDatainheritFromWidgetOfExactType(_LocalizationsScope) was called before ProfileScreen.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 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);
}
}

最佳答案

您需要来自的上下文

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

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

然后再次
_onLoading(context) 

和使用
showDialog(
context: context, //The context from Widget Build(BuildContext context)...

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

关于dart - Flutter升级:在更新最新版本的Flutter之后,先前的功能不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52498642/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com