From 4d1af9144d1fb5fd9d728f25ff8fafd413f20c7c Mon Sep 17 00:00:00 2001 From: Russ Biggs Date: Wed, 12 May 2021 09:55:07 -0600 Subject: [PATCH] await camera capture to prevent multiple button clicks resolves #118 --- lib/ui/camera/camera_screen.dart | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/ui/camera/camera_screen.dart b/lib/ui/camera/camera_screen.dart index 54d0cc4..1a609ba 100644 --- a/lib/ui/camera/camera_screen.dart +++ b/lib/ui/camera/camera_screen.dart @@ -36,6 +36,7 @@ class _CameraScreenState extends State { String imgPath; double _position; String _pointId; + bool awaitingCapture = false; Future initCamera(CameraDescription cameraDescription) async { if (cameraController != null) { @@ -118,9 +119,7 @@ class _CameraScreenState extends State { color: Color.fromRGBO(0, 0, 0, 0.6), ), backgroundColor: Color.fromRGBO(255, 255, 255, 0.2), - onPressed: () { - onCapture(context); - }, + onPressed: awaitingCapture ? null : () => onCapture(context), ), floatingActionButtonLocation: FloatingActionButtonLocation.centerFloat, ); @@ -132,7 +131,9 @@ class _CameraScreenState extends State { final name = DateTime.now(); final path = "${p.path}/$name.png"; try { + awaitingCapture = true; XFile img = await cameraController.takePicture(); + awaitingCapture = false; await img.saveTo(path); Navigator.pushNamed(context, PreviewScreen.routeName, arguments: PreviewScreenArguments(widget.surveyItemId, path,