【发布时间】:2022-01-15 23:11:10
【问题描述】:
在 Flutter 中,如何在立即调用另一个函数之前等待屏幕的初始化?
对于进一步的上下文,当我按下按钮时,我会打开一个对话框,其中包含来自相机包的相机预览,其中一个容器框堆叠在相机预览的顶部以充当“取景器”。然后我想从 rect_getter 包中调用 RectGetter 函数来定位容器框屏幕上的坐标,但是我需要等待先构建 CameraPreview 和容器框。
下面是我调用的相机对话框,需要在调用RectGetter函数之前构建:
cameraDialog() async {
await showDialog(
barrierDismissible: false,
context: context,
builder: (_) => AlertDialog(
insetPadding: EdgeInsets.all(5.0),
contentPadding: EdgeInsets.all(3.0),
content: FutureBuilder<void>(
future: _initializeControllerFuture,
builder: (context, snapshot) {
if (snapshot.connectionState == ConnectionState.done) {
return Stack(
children: [
cameraPrevew and containers etc...
我知道这篇文章: How to run code after some delay in Flutter?
所有这些解决方案都只是调用一个延迟计时器,我认为它会起作用,但是我正在寻找一个更动态的解决方案。
【问题讨论】: