-
Notifications
You must be signed in to change notification settings - Fork 92
Unhandled Exception: type 'Null' is not a subtype of type 'Uint8List' in type cast #78
Description
class _FaceCameraViewState extends State {
File? capturedImage;
FaceCameraController? controller;
@OverRide
void initState() {
super.initState();
initCamera();
}
Future initCamera() async {
final status = await Permission.camera.status;
if (status.isGranted) {
_startCamera();
} else if (status.isDenied) {
final requestStatus = await Permission.camera.request();
if (requestStatus.isGranted) {
startCamera();
} else if (requestStatus.isPermanentlyDenied) {
showDialog(
context: context,
builder:
() => AlertDialog(
title: const Text("Camera Permission Required"),
content: const Text(
"Camera access has been disabled. Please enable it in Settings to continue.",
),
actions: [
TextButton(
onPressed: () {
openAppSettings();
Navigator.of(context).pop();
},
child: const Text("Open Settings"),
),
],
),
);
} else {
debugPrint("Camera permission denied.");
}
}
}
void _startCamera() async {
await FaceCamera.initialize();
controller = FaceCameraController(
autoCapture: true,
defaultCameraLens: CameraLens.front,
onCapture: (File? image) {
if (image != null) {
setState(() => capturedImage = image);
}
},
onFaceDetected: (Face? face) {},
);
setState(() {});
}
@OverRide
Widget build(BuildContext context) {
if (controller == null) {
return const Center(child: CircularProgressIndicator());
}
return SmartFaceCamera(
controller: controller!,
messageBuilder: (context, face) {
if (face == null) {
return _message('Place your face in the camera');
}
if (!face.wellPositioned) {
return _message('Center your face in the square');
}
return const SizedBox.shrink();
},
);
}
Widget _message(String msg) => Padding(
padding: const EdgeInsets.symmetric(horizontal: 55, vertical: 15),
child: Text(
msg,
textAlign: TextAlign.center,
style: const TextStyle(
fontSize: 14,
height: 1.5,
fontWeight: FontWeight.w400,
),
),
);
@OverRide
void dispose() {
controller?.dispose();
super.dispose();
}
}
Here is my code , am getting above error