gpt4 book ai didi

Flutter - 有没有办法在 InitState 中加载异步方法?

转载 作者:行者123 更新时间:2023-12-04 07:29:51 26 4
gpt4 key购买 nike

这个问题在这里已经有了答案:





Is there a way to load async data on InitState method?

(14 个回答)


2个月前关闭。




Flutter - 有没有办法在 InitState 上加载异步方法?我想在 iniState() 中调用异步方法;但它不起作用......
我正在寻找一种在 InitState 方法上加载异步数据的方法,在构建方法运行之前我需要一些数据。我需要执行构建方法,直到 Stream 运行。

    @override
void initState () {
super.initState();

//here i want to call async function
}

最佳答案

您可以创建一个单独的方法并可以在 initState() 中调用。此外,您可以使用 WidgetBinding 来调用这样的函数。

void initState() {
WidgetsBinding.instance.addPostFrameCallback((_) => {
your_method();
// TODO: implement initState
super.initState();
}

关于Flutter - 有没有办法在 InitState 中加载异步方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68006158/

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