showImage method
Implementation
Widget showImage() {
return ValueListenableBuilder<String?>(
valueListenable: _latestImagePathNotifier,
builder: (context, latestImagePath, _) {
if (latestImagePath == null) {
// If there is no latest image, display the camera preview or return null.
return ValueListenableBuilder<CameraController?>(
valueListenable: _cameraControllerNotifier,
builder: (context, cameraController, _) {
if (cameraController == null) {
return Center(child: Text("Loading Camera..."));
}
if (!cameraController.value.isInitialized) {
// Wait for the camera initialization to complete before showing CameraPreview.
return FutureBuilder<void>(
future: cameraController.initialize(),
builder: (context, snapshot) {
if (snapshot.connectionState == ConnectionState.done) {
return Stack(
children: [
Container(
height: 300,
width: 400,
child: CameraPreview(cameraController),
),
Center(child: showTimer()), // Show the timer above the CameraPreview
],
);
} else {
// While waiting for initialization, show a progress indicator.
return Center(child: CircularProgressIndicator());
}
},
);
} else {
// Camera is already initialized, show CameraPreview.
return Stack(
children: [
Container(
height: 300,
width: 400,
child: CameraPreview(cameraController),
),
showTimer(), // Show the timer above the CameraPreview
],
);
}
},
);
} else {
// If there is a latest image, display it using the Image widget.
return Image.file(
File(latestImagePath),
width: 200,
height: 200,
fit: BoxFit.cover,
);
}
},
);
}