From 074cb7715c90a47ef7ee7eed274f4bd494c923c0 Mon Sep 17 00:00:00 2001 From: Bharat Biradar <62872048+bharat-biradar@users.noreply.github.com> Date: Tue, 23 Feb 2021 16:00:56 +0530 Subject: [PATCH 1/5] Update takePicture() docs --- .../cookbook/plugins/picture-using-camera.md | 22 +++++-------------- 1 file changed, 6 insertions(+), 16 deletions(-) diff --git a/src/docs/cookbook/plugins/picture-using-camera.md b/src/docs/cookbook/plugins/picture-using-camera.md index 66404b2efa..9b017b26e3 100644 --- a/src/docs/cookbook/plugins/picture-using-camera.md +++ b/src/docs/cookbook/plugins/picture-using-camera.md @@ -179,15 +179,14 @@ FutureBuilder( ## 5. Take a picture with the `CameraController` You can use the `CameraController` to take pictures using the -[`takePicture()`][] method. In this example, +[`takePicture()`][] method. The [`takePicture()`][] method returns a [`Xfile`](https://pub.dev/documentation/camera/latest/camera/XFile-class.html) which is a cross-platform simplified File abstraction. In this example, create a `FloatingActionButton` that takes a picture using the `CameraController` when a user taps on the button. -Saving a picture requires 3 steps: +Taking a picture requires 2 steps: - 1. Ensure the camera is initialized - 2. Construct a path that defines where the picture should be saved - 3. Use the controller to take a picture and save the result to the path + 1. Ensure the camera is initialized. + 2. Use the controller to take a picture and it returns a Future. It is good practice to wrap these operations in a `try / catch` block in order to handle any errors that might occur. @@ -204,17 +203,8 @@ FloatingActionButton( // Ensure that the camera is initialized. await _initializeControllerFuture; - // Construct the path where the image should be saved using the path - // package. - final path = join( - // Store the picture in the temp directory. - // Find the temp directory using the `path_provider` plugin. - (await getTemporaryDirectory()).path, - '${DateTime.now()}.png', - ); - - // Attempt to take a picture and log where it's been saved. - await _controller.takePicture(path); + // Attempt to take a picture. + final image = await _controller.takePicture(); } catch (e) { // If an error occurs, log the error to the console. print(e); From 9e9cc88613683fdb6b3af4d42abf05c8659c7cc8 Mon Sep 17 00:00:00 2001 From: Bharat Biradar <62872048+bharat-biradar@users.noreply.github.com> Date: Tue, 23 Feb 2021 16:15:44 +0530 Subject: [PATCH 2/5] Update: #5 takePicture() explanation --- src/docs/cookbook/plugins/picture-using-camera.md | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/docs/cookbook/plugins/picture-using-camera.md b/src/docs/cookbook/plugins/picture-using-camera.md index 9b017b26e3..e16b2b96de 100644 --- a/src/docs/cookbook/plugins/picture-using-camera.md +++ b/src/docs/cookbook/plugins/picture-using-camera.md @@ -179,8 +179,9 @@ FutureBuilder( ## 5. Take a picture with the `CameraController` You can use the `CameraController` to take pictures using the -[`takePicture()`][] method. The [`takePicture()`][] method returns a [`Xfile`](https://pub.dev/documentation/camera/latest/camera/XFile-class.html) which is a cross-platform simplified File abstraction. In this example, -create a `FloatingActionButton` that takes a picture +[`takePicture()`][] method. The [`takePicture()`][] method returns a [`Xfile`](https://pub.dev/documentation/camera/latest/camera/XFile-class.html) which is a cross-platform simplified File abstraction. In android and IOS implementation the image taken is stored in their respective cache directories. The path of the Xfile returned points to the image stored in the cache directory of the device. + +In this example, create a `FloatingActionButton` that takes a picture using the `CameraController` when a user taps on the button. Taking a picture requires 2 steps: @@ -203,7 +204,8 @@ FloatingActionButton( // Ensure that the camera is initialized. await _initializeControllerFuture; - // Attempt to take a picture. + // Attempt to take a picture and get the file + // where the image was saved. final image = await _controller.takePicture(); } catch (e) { // If an error occurs, log the error to the console. From 8169889f31d5ee945b8fef0f6dac46e5a2376bf2 Mon Sep 17 00:00:00 2001 From: "Shams Zakhour (ignore Sfshaza)" <44418985+sfshaza2@users.noreply.github.com> Date: Tue, 23 Feb 2021 09:18:16 -0800 Subject: [PATCH 3/5] Update src/docs/cookbook/plugins/picture-using-camera.md --- src/docs/cookbook/plugins/picture-using-camera.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/docs/cookbook/plugins/picture-using-camera.md b/src/docs/cookbook/plugins/picture-using-camera.md index e16b2b96de..de5293b1af 100644 --- a/src/docs/cookbook/plugins/picture-using-camera.md +++ b/src/docs/cookbook/plugins/picture-using-camera.md @@ -179,7 +179,13 @@ FutureBuilder( ## 5. Take a picture with the `CameraController` You can use the `CameraController` to take pictures using the -[`takePicture()`][] method. The [`takePicture()`][] method returns a [`Xfile`](https://pub.dev/documentation/camera/latest/camera/XFile-class.html) which is a cross-platform simplified File abstraction. In android and IOS implementation the image taken is stored in their respective cache directories. The path of the Xfile returned points to the image stored in the cache directory of the device. +[`takePicture()`][] method, which returns an [`Xfile`][], +a cross-platform, simplified `File` abstraction. +On both Android and IOS, the new image is stored in their +respective cache directories, +and the `path` to that location is returned in the `Xfile`. + +[`Xfile`]: {{site.pub}}/documentation/camera/latest/camera/XFile-class.html In this example, create a `FloatingActionButton` that takes a picture using the `CameraController` when a user taps on the button. From eb5142734ffbe133c99ce9957e2208a7aa64cab4 Mon Sep 17 00:00:00 2001 From: "Shams Zakhour (ignore Sfshaza)" <44418985+sfshaza2@users.noreply.github.com> Date: Tue, 23 Feb 2021 09:18:26 -0800 Subject: [PATCH 4/5] Update src/docs/cookbook/plugins/picture-using-camera.md --- src/docs/cookbook/plugins/picture-using-camera.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/docs/cookbook/plugins/picture-using-camera.md b/src/docs/cookbook/plugins/picture-using-camera.md index de5293b1af..9ff7912e7f 100644 --- a/src/docs/cookbook/plugins/picture-using-camera.md +++ b/src/docs/cookbook/plugins/picture-using-camera.md @@ -192,8 +192,8 @@ using the `CameraController` when a user taps on the button. Taking a picture requires 2 steps: - 1. Ensure the camera is initialized. - 2. Use the controller to take a picture and it returns a Future. + 1. Ensure that the camera is initialized. + 2. Use the controller to take a picture and ensure that it returns a `Future`. It is good practice to wrap these operations in a `try / catch` block in order to handle any errors that might occur. From 3660085a436bfa5efc9203f07c5cc19a9385ad97 Mon Sep 17 00:00:00 2001 From: "Shams Zakhour (ignore Sfshaza)" <44418985+sfshaza2@users.noreply.github.com> Date: Tue, 23 Feb 2021 09:18:41 -0800 Subject: [PATCH 5/5] Update src/docs/cookbook/plugins/picture-using-camera.md --- src/docs/cookbook/plugins/picture-using-camera.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/docs/cookbook/plugins/picture-using-camera.md b/src/docs/cookbook/plugins/picture-using-camera.md index 9ff7912e7f..8870f5edb0 100644 --- a/src/docs/cookbook/plugins/picture-using-camera.md +++ b/src/docs/cookbook/plugins/picture-using-camera.md @@ -210,8 +210,8 @@ FloatingActionButton( // Ensure that the camera is initialized. await _initializeControllerFuture; - // Attempt to take a picture and get the file - // where the image was saved. + // Attempt to take a picture and then get the location + // where the image file is saved. final image = await _controller.takePicture(); } catch (e) { // If an error occurs, log the error to the console.