title: I Can't get flutter camera plugin to work from a second screen
body: <p>I have been trying to get the flutter camera plugin to work for almost a week now but I couldn't.
  Every time the camera is not initialized no matter what workaround I do.</p>
  <p><strong>Can any one help please.</strong></p>
  <pre><code>class CameraPage extends StatefulWidget {
        const CameraPage({Key? key,}) : super(key: key); @override
        State&lt;CameraPage&gt; createState() =&gt; _CameraPageState();
      }
      
      class _CameraPageState extends State&lt;CameraPage&gt; {
        List&lt;CameraDescription&gt;? cameras;
        CameraDescription? camera;
        CameraController? cameraController;
        CameraDescription? firstCamera() {
          camera = cameras![1];
          return camera;
        }
      
        Future getAvailableCameras() async {
          cameras = await availableCameras();
          camera = firstCamera();
        }
      
        Future setDefaultCamera() async {
          cameraController = CameraController(
              Provider.of&lt;CameraProvider&gt;(context).camer!, ResolutionPreset.medium);
          cameraController?.initialize();
          return cameraController;
        }
      
  
        @override
        Widget build(BuildContext context) {
          return Scaffold(
            body: FutureBuilder(
                future: setDefaultCamera(),
                builder: ((context, snapshot) {
                  if (snapshot.hasData) {
                    return Container(
                        width: 450,
                        color: Colors.red,
                        height: 450,
                        child: CameraPreview(cameraController!));
                  } else {
                    return const Center(child: CircularProgressIndicator());}})),);}}
  </code></pre>