How to take picture using the camera in Flutter.
- Add the dependencies
dependencies:
flutter:
sdk: flutter
camera:
path_provider:
path: - Make a list of all available cameras
WidgetsFlutterBinding.ensureInitialized();
final cameras = await availableCameras();
final firstCamera = cameras.first; - Create and initialize the Cameracontroller
CameraController _cameraController;
@override
void initState() {
// TODO: implement initState
super.initState();
_cameraController = CameraController(cameras[0], ResolutionPreset.high);
cameraValue = _cameraController.initialize();
}
4. Take a picture with the CameraController
FloatingActionButton(
child: Icon(Icons.camera_alt),
onPressed: () async {
await _initializeControllerFuture;
final image = await _controller.takePicture();
},
)
5.Display the picture with an Image
widget
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text('Display the Picture')),
body: Image.file(File(imagePath)),
);
}
For more detailed information please visit https://flutter.dev/docs/cookbook/plugins/picture-using-camera.