3. Create and initialize the CameraController

Once you have a camera, use the following steps to
create and initialize a CameraController.
This process establishes a connection to
the device’s camera that allows you to control the camera
and display a preview of the camera’s feed.

Create a StatefulWidget with a companion State class.

Add a variable to the State class to store the CameraController.

Add a variable to the State class to store the Future
returned from CameraController.initialize().

Create and initialize the controller in the initState() method.

Dispose of the controller in the dispose() method.

Warning:
  If you do not initialize the CameraController,
  you cannot use the camera to display a preview and take pictures.

4. Use a CameraPreview to display the camera’s feed

Next, use the CameraPreview widget from the camera package to
display a preview of the camera’s feed.