this flutter code used to work but after an update it does not work anymore and I absolutely have been struggling for hours on it. The error says
LateInitializationError: Field '_camera@26505073' has not been initialized.
Here is my Code
class _CameraFlowState extends State<CameraFlow> {
// 2
late CameraDescription _camera;
bool _shouldShowCamera = false;
int len = 0;
// 3
List<MaterialPage> get _pages {
return [
// Show Gallery Page
MaterialPage(
child: GalleryPage(
shouldLogOut: widget.shouldLogOut,
shouldShowCamera: () => _toggleCameraOpen(true))),
// Show Camera Page
if (_shouldShowCamera)
MaterialPage(
child: CameraPage(
camera: _camera,
didProvideImagePath: (imagePath) {
_toggleCameraOpen(false);
}))
];
}
@override
void initState() {
super.initState();
_getCamera();
}
@override
Widget build(BuildContext context) {
// 4
return Navigator(
pages: _pages,
onPopPage: (route, result) => route.didPop(result),
);
}
// 5
void _toggleCameraOpen(bool isOpen) {
setState(() {
_shouldShowCamera = isOpen;
});
}
Future<void> _getCamera() async {
final camerasList = await availableCameras();
setState(() {
final firstCamera = camerasList.first;
_camera = firstCamera;
});
}
}
I tried doing this
CameraDescription? _camera;
But then I get
Null check operator used on a null value.
How can I fix this problem? Please help me out...