Flutter Framework - Refractored Camera Widget
For those who are new to the Flutter Framework and looking to learn and use the camera, the Take a picture using the camera cookbook is a great place to start. I followed the instructions and it worked fine. The next step for me was to refactor the code so that the camera widget was in its own dart file. How to Avoid Getting "LateInitializationError: Field 'controller' has not been initialized" Error The key is to create async function to wait for the camera to be fully initialized and use it with the already written FutureBuilder . Future < void > initCamera () async { final cameras = await availableCameras (); // Get a specific camera from the list of available cameras. final firstCamera = cameras . first ; // To display the current output from the Camera, // create a CameraController. _controller = CameraController ( // Get a specific camera from the list of available cameras. firstCamera , // Define the r...