In Flutter how do I await the initialization of a screen before immediately calling another function?
For further context, when I press a button I open a dialog box that contains a Camera Preview from the camera package with a container box stacked on top of the Camera Preview to act as a 'view finder'. I then want to call the RectGetter function from the rect_getter package to locate the coordinates on the screen of the container box, however I need to wait for the CameraPreview and container box to be constructed first.
Below is the camera dialog I call that I need to be constructed before calling the RectGetter Function:
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...
I am aware of this post: How to run code after some delay in Flutter?
All these solutions just call a delay timer, which I suppose would work, however I'm looking for a more dynamic solution.