我以前见过这个问题,但问题总是功能的子集。我正在寻找完全相同的生命周期事件。我可以说得更具体。
我知道 Flutter 小部件中存在的是
onCreate
/ viewDidLoad
=initState
onDestroy
/ viewDidUnload
=dispose
这些是我想了解的生命周期事件(对于当前可见的 widget/route,而不是整个应用程序):
onResume
/viewWillAppear
在当前可见的小部件上被触发内部导航(在应用程序内导航)
A。您将路线/小部件推入堆栈
b. 您导航回路线/小部件(已经位于导航堆栈的背面)
外部导航(应用程序的后台和前台)
A。您从后台打开应用程序(路线/小部件是显示给用户的)
b. 您打开屏幕(电源按钮)并且应用程序已打开
onPause
/在当前可见的小部件上viewDidDisappear
被触发内部导航(在应用程序内导航)
A。您离开小部件/路线继续前进
b. 您可以通过关闭小部件/在堆栈中向后浏览来离开该小部件
外部导航(应用程序的后台和前台)
A。您将应用程序置于后台(并且路线/小部件是向用户显示的) b.您在应用程序打开的情况下关闭屏幕(电源按钮)
安装 Go 后出现以下错误asdf
and trying to open a Go project.
Failed to find the "go" binary in either\xe3\x80\x82GOROOT() or PATH(/usr/bin:/bin:/usr/sbin:/sbin). Check PATH, or Install Go and reload the window.\n
Run Code Online (Sandbox Code Playgroud)\n 在 Javascript 中,你可以使用以下方法将回调转换为 Promise:
function timeout(time){
return new Promise(resolve=>{
setTimeout(()=>{
resolve('done with timeout');
}, time)
});
}
Run Code Online (Sandbox Code Playgroud)
在 Flutter 中这可能吗?
例子:
// I'd like to use await syntax, so I make this return a future
Future<void> _doSomething() async {
// I'm call a function I don't control that uses callbacks
// I want to convert it to async/await syntax (Future)
SchedulerBinding.instance.addPostFrameCallback((_) async {
// I want to do stuff in here and have the return of
// `_doSomething` await it …
Run Code Online (Sandbox Code Playgroud)