Last active
March 31, 2019 16:48
-
-
Save redbluenat/68f20104610ed3ce4499cf53113fc29e 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
void onTakePictureButtonPressed() { | |
takePicture().then((String filePath) { | |
if (mounted) { | |
setState(() { | |
showCamera = false; | |
imagePath = filePath; | |
}); | |
} | |
}); | |
} | |
Future<String> takePicture() async { | |
if (!controller.value.isInitialized) { | |
return null; | |
} | |
final Directory extDir = await getApplicationDocumentsDirectory(); | |
final String dirPath = '${extDir.path}/Pictures/flutter_test'; | |
await Directory(dirPath).create(recursive: true); | |
final String filePath = '$dirPath/${timestamp()}.jpg'; | |
if (controller.value.isTakingPicture) { | |
return null; | |
} | |
try { | |
await controller.takePicture(filePath); | |
} on CameraException catch (e) { | |
return null; | |
} | |
return filePath; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment