Created
December 12, 2019 08:24
-
-
Save BoshiLee/b809791bfd2e082f151ca5a65ba5bacf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FloatingActionButton( | |
child: Icon(Icons.camera_alt), | |
// Provide an onPressed callback. | |
onPressed: () async { | |
// Take the Picture in a try / catch block. If anything goes wrong, | |
// catch the error. | |
try { | |
// 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); | |
} catch (e) { | |
// If an error occurs, log the error to the console. | |
print(e); | |
} | |
}, | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment