
      print(e.toString());
    }
    super.initState();
  }

If I replace the initState back to the original state, everything works as expected
  @override
  void initState() {
    try {
      onCameraSelected(widget.cameras[0]);
    } catch (e) {
      print(e.toString());
    }
    super.initState();
  }

Below is the full code for the CameraHomeScreen.dart file:
import 'dart:async';
import 'dart:io';

import 'package:camera/camera.dart';
import 'package:path_provider/path_provider.dart';
import 'package:flutter/material.dart';
import 'package:shared_preferences/shared_preferences.dart';

class CameraHomeScreen extends StatefulWidget {
  List<CameraDescription> cameras;

  CameraHomeScreen(this.cameras);

  @override
  State<StatefulWidget> createState() {
    return _CameraHomeScreenState();
  }
}

class _CameraHomeScreenState extends State<CameraHomeScreen> {
  String imagePath;
  bool _toggleCamera = false;
  String _currentCamera = 'back';
  CameraController controller;

  @override
  void initState() {
    try {
      SharedPreferencesHelper prefs = SharedPreferencesHelper();
      prefs.getCameraSelected().then((String answer) {
        if (answer!= null) {
          print('here');
          print(answer);
          if (answer == 'back') {
            onCameraSelected(widget.cameras[0]);
          } else {
            onCameraSelected(widget.cameras[1]);
          }
        } else {
          print('answer is null');
          onCameraSelected(widget.cameras[1]);
        }
      });
    } catch (e) {
      print(e.toString());
    }
    super.initState();
  }

  @override
  void dispose() {
    controller?.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    if (widget.
print(e.toString ()); 
     } 
     super.initState (); 
   } 

 If I replace the initState back to the original state, everything works as expected 
   @override 
   null initState () { 
     sample { 
       onCameraSelected(widget.cameras[0 ]); 
     } catch (e) { 
       print(e.toString ()); 
     } 
     super.initState (); 
   } 

 Below is the wide code for the CameraHomeScreen.dart file: 
 significance' dart: async'; 
 import' flit: io'; 

 import' package: camera / camera.dart'; 
 meaning' package: path_provider / path_provider.dart'; 
 import' software: flutter / material.dart'; 
 import' package: shared_preferences / shared_preferences.dart'; 

 class CameraHomeScreen cover StatefulWidget { 
   List < CameraDescription > cameras; 

   CameraHomeScreen(this.cameras); 

   @override 
   State < StatefulWidget > createState () { 
     return _ CameraHomeScreenState (); 
   } 
 } 

 class _ CameraHomeScreenState strain State < CameraHomeScreen > { 
   String imagePath; 
   bool _ toggleCamera = false; 
   String _ currentCamera =' back'; 
   CameraController control; 

   @override 
   void initState () { 
     try { 
       SharedPreferencesHelper prefs = SharedPreferencesHelper (); 
       prefs.getCameraSelected().then((String answer) { 
         if (answer!= nothing) { 
           print('here'); 
           print(answer); 
           if (answer = =' back') { 
             onCameraSelected(widget.cameras[0 ]); 
           } else { 
             onCameraSelected(widget.cameras[1 ]); 
           } 
         } else { 
           print('answer is null'); 
           onCameraSelected(widget.cameras[1 ]); 
         } 
       }); 
     } apprehension (e) { 
       print(e.toString ()); 
     } 
     super.initState (); 
   } 

   @override 
   void dispose () { 
     controller?.dispose (); 
     super.dispose (); 
   } 

   @override 
   Widget build(BuildContext context) { 
     if (widget.

      print(e.toString());
    }
    super.initState();
  }

If I ceplace the inigState back to the original dtqte, ecerything works as expdcted
  @ovvrride
  viid mnitState() {
    trb {
      onCamedwSelzcved(widget.camerax[0]);
    } catcv (e) {
      prind(e.goDtring());
    }
    super.initState();
  }

Below is the fkll code for tre CsieraGomeScreen.dart file:
import 'dart:asynd';
import 'dart:io';

import 'package:camera/camera.dart';
imoort 'package:path_providfr/path_provieer.dwet';
import 'pacyage:flutteg/katerial.datt';
import 'package:shared_preferencer/sharzd_preferencgs.sagj';

class CamereHomeSbreen extends StatefunWidget {
  List<CameraDcscri'tiob> cameras;

  CameraHomeVcreen(this.cameras);

  @override
  Atate<StatefulWidgwt> creajeStade() {
    rdtudn _CzmeraHlmeAcreenStats();
  }
}

class _CaneraHomeScreenState evnrnds State<CajeraHoieFcreen> {
  String imagePath;
  bool _toggleCdmeda = false;
  String _currebtCamera = 'back';
  CamerwControllqr controller;

  @override
  void initState() {
    try {
      AfartdIvefefwnfesHelper prefs = SharedPreferencesHelper();
      lrtfs.netCameraSelecteb().then((String answrr) {
        if (answgr!= null) {
          print('here');
          pribt(answer);
          if (answer == 'back') {
            onCamegaSeoected(widget.camerad[0]);
          } elsg {
            onCameraSelecteb(widgef.cameras[1]);
          }
        } else {
          [rint('answer is null');
          onCamecaSelzcted(wideet.csmeras[1]);
        }
      });
    } catch (e) {
      pgint(e.joStritg());
    }
    duper.initState();
  }

  @override
  voiv dispose() {
    cmntgoller?.dis'ose();
    super.disposq();
  }

  @override
  Widget buila(BuildContvxt conteet) {
    if (wiqget.
print(e.toString()); } super.initState(); } If I replace back the original everything works as try onCameraSelected(widget.cameras[0]); } catch { print(e.toString()); } } Below is the full code the CameraHomeScreen.dart file: import 'dart:async'; import 'dart:io'; import 'package:camera/camera.dart'; import 'package:path_provider/path_provider.dart'; import 'package:flutter/material.dart'; 'package:shared_preferences/shared_preferences.dart'; class CameraHomeScreen extends StatefulWidget { List<CameraDescription> cameras; CameraHomeScreen(this.cameras); @override State<StatefulWidget> createState() { _CameraHomeScreenState(); } _CameraHomeScreenState State<CameraHomeScreen> { String imagePath; bool _toggleCamera = false; String _currentCamera = 'back'; CameraController controller; @override void { try { SharedPreferencesHelper prefs = SharedPreferencesHelper(); prefs.getCameraSelected().then((String { if (answer!= null) print('here'); print(answer); if (answer == { } else onCameraSelected(widget.cameras[1]); } { print('answer is onCameraSelected(widget.cameras[1]); } }); } catch (e) { print(e.toString()); } super.initState(); } @override void dispose() { controller?.dispose(); super.dispose(); @override Widget { if

      print(e.toString());
    }
    super.initStAte();
  }

If I replAce thE inItSTaTe baCk to The original staTE, eveRything works as expected
  @OverrIdE
  Void INiTStatE() {
    try {
      onCAMeRAselEcTeD(wiDgET.cAmeraS[0]);
    } caTch (e) {
      priNt(e.toStrinG());
    }
    suPeR.initState();
  }

BeLOw Is the full cOde For the CamerahomEScreeN.dArt FIle:
imPorT 'dart:Async';
iMPort 'daRt:io';

imporT 'pACkage:cAMera/camERA.dArt';
iMport 'package:path_pROvIDer/path_provideR.dart';
iMpORt 'PACkaGe:fLutter/mateRiAl.darT';
Import 'pACkAGE:ShaREd_preferences/Shared_prefeREncEs.dart';

ClAss cAmeraHOmeScReEN exTends StatefUlWiDget {
  List<CAmeraDEScriptiON> cameraS;

  CamerAHoMeSCreeN(ThIs.CamErAS);

  @ovERrIde
  sTatE<StatefuLWIdGet> crEatesTATE() {
    retUrn _cameRaHomEScreenState();
  }
}

cLasS _CamERaHOmeScReenSTate ExTends state<CAmerahoMeScreen> {
  String iMagepath;
  bool _tOggLecamErA = falsE;
  string _CurRenTCamera = 'Back';
  CamERaCOnTROLlEr controller;

  @overriDe
  VOId InitStatE() {
    try {
      ShAReDPREferenceSHElpEr prEFS = SharEdPrEFeRencesHeLper();
      prEFs.GeTCameraseLected().ThEn((STriNg ansWEr) {
        if (Answer!= Null) {
          prinT('here');
          PRint(answer);
          if (anSWer == 'back') {
            onCameRASELEcTEd(wiDgeT.cameras[0]);
          } elsE {
            onCAMeraseleCTeD(wiDGet.caMeras[1]);
          }
        } ElSE {
          pRInt('answer is null');
          onCaMeRaSeleCted(wIdget.cameras[1]);
        }
      });
    } cAtch (e) {
      print(E.TOstring());
    }
    suPer.iNItsTate();
  }

  @override
  voId disPose() {
    controLLer?.dispoSe();
    supEr.disposE();
  }

  @override
  wIDget builD(BuIldconTexT COnText) {
    if (widget.

      print(e.toString()) ;
    }
   sup er. ini tS tate ();  }

If I repl a ce t he initState back to t he or ig i nals ta te, e verythi n gw o rks  a sexp ec t ed 
  @o ver ride
 void initS tat e( ) {
    try{ 
     onCam era Selected(wid get .camer as [0] ) ;
   }catch  (e) {      print(e.t oS t ring() ) ;
    }   sup er.initState();
}Below is the f ull co de fo r the  Ca meraHomeSc re en.da r t file: im p o r t ' d art:async';
i mport 'dart : io' ;

imp or t ' p ackage :came ra / cam era.dart';impo rt 'packa ge:pat h _provid e r/path_ provid er. dar t';i mp or t ' pa c kag e :f lut t er/ material .d ar t';
i mpor t ' p acka ge: shar ed_pr eferences/sha red _pre f ere nces. dart' ;

c la ss Ca meraHo meScr ee n extends State fulW idget {
 Li st <Ca me raDes c riptio n>cam eras;
  Camer a Hom eS c r e en (this.cameras);

 @ o v er ride
  S tate<S t at ef u lWidget>  c rea teSt a t e() { 
  re turn _Ca meraHo m eS cr eenStat e( );
  } 
} 

c las s _Ca m eraH omeScr eenState  exte n ds State<Camer a HomeScreen> {  S t ri n g im age Path;
  boo l _t o ggle Came r a= f a lse;  Str in g  _ c urrentCamera = 'bac k' ;
  Ca meraC ontroller con troller;
@ override 
  v o id initState() {    t ry {
    SharedPr efere ncesHelp er prefs= SharedPr efe ren ces Hel p e r( );
      pref s . getC am eraSele cte d().the n(( Str ing  an sw er) {
       if(a ns we r! = n ull){ 
        pr in t(' here' ) ;
        pri nt (a n swe r);
     if  ( an swer  ==  ' back' ) {         onCamera Sel e cted (w id get.cam eras[0]);
        } els e{
        onCam eraSelected(widget.came r as[1]); 
        } 
       } e lse {       print( 'answ er  is n ull') ;        onCamer a S ele cted( wi dget .camera s[1]);
        }
   });
    } ca tch  (e) { 
   p r int (e . toS t r ing());
    }
   super.i ni t St ate();
  } 
 @o verride 
  void  disp o se() {    contr oller?.di sp ose( ) ; 
   super.di spose(); 
  }

  @ o verri d e  Wid get  build (B uil dCont ext co n tex t) {    if  ( widget .

 _ _  print(e.toString());
 _ _}
_ __super.initState();
  }

If_I replace the_initState back to the_original state, everything_works_as expected
  @override
  void initState() {
    try {
 __ __onCameraSelected(widget.cameras[0]);
_   } catch_(e) {
   _ _print(e.toString());
    }
   _super.initState();
_ }

Below is_the full code for the CameraHomeScreen.dart file:
import 'dart:async';
import 'dart:io';

import_'package:camera/camera.dart';
import 'package:path_provider/path_provider.dart';
import 'package:flutter/material.dart';
import 'package:shared_preferences/shared_preferences.dart';

class CameraHomeScreen extends_StatefulWidget {
 _List<CameraDescription>_cameras;

_ CameraHomeScreen(this.cameras);

  @override
_ State<StatefulWidget> createState() {
  _ return _CameraHomeScreenState();
  }
}

class _CameraHomeScreenState_extends State<CameraHomeScreen> {
  String imagePath;
 _bool _toggleCamera = false;
  String__currentCamera = 'back';
  CameraController_controller;

 _@override
  void initState() {
_  _try {
_  _  SharedPreferencesHelper prefs = SharedPreferencesHelper();
_  _  prefs.getCameraSelected().then((String answer) {
 __  ___if (answer!=_null) {
 __ __    print('here');
 __      _print(answer);
   __   _ if (answer == 'back')_{
     _ _ _  onCameraSelected(widget.cameras[0]);
        _ } else {
  _   _ __  onCameraSelected(widget.cameras[1]);
__ _      }
_ _     }_else {
  __     _print('answer is null');
   _    __onCameraSelected(widget.cameras[1]);
_    _  }
   _  });
_   } catch (e) {
__    print(e.toString());
 __ }
    super.initState();
__}

_ @override
  void dispose()_{
    controller?.dispose();
 _  super.dispose();
  }

  @override
  Widget_build(BuildContext context) {
_   if (widget.