captureImage method
Yêu cầu native code chụp ảnh. Trả về đường dẫn (String) của file ảnh đã lưu nếu thành công, ngược lại trả về null.
Implementation
Future<String?> captureImage() async {
try {
// Gọi method 'captureImage' trên MethodChannel.
final String? filePath = await _channel.invokeMethod('captureImage');
debugPrint('CameraController: Ảnh đã được chụp và lưu tại: $filePath');
return filePath;
} on PlatformException catch (e) {
// Xử lý lỗi nếu có vấn đề khi gọi xuống native.
debugPrint("CameraController: Chụp ảnh thất bại: '${e.message}'.");
// Bạn có thể chọn re-throw lỗi hoặc trả về null tùy theo cách xử lý lỗi ở UI.
// throw Exception("Failed to capture image: ${e.message}");
return null;
}
}