showPreview<T> static method
Future<T?>
showPreview<T>({
- required BuildContext context,
- required MediaStream stream,
- required bool isVideo,
Implementation
static Future<T?> showPreview<T>({
required BuildContext context,
required web.MediaStream stream,
required bool isVideo,
}) async {
final completer = Completer<T?>();
bool isRecording = false;
// Show the overlay
final overlay = OverlayEntry(
builder: (context) => CameraPreviewOverlay(
stream: stream,
isVideo: isVideo,
isRecording: isRecording,
onCapture: () {
if (!completer.isCompleted) {
if (isVideo) {
// Start recording
// We'll handle this in the implementation
completer.complete(true as T);
} else {
// Capture photo
completer.complete(true as T);
}
}
},
onStopRecording: isVideo
? () {
if (!completer.isCompleted) {
completer.complete(false as T);
}
}
: null,
onCancel: () {
if (!completer.isCompleted) {
completer.complete(null);
}
},
),
);
// Insert the overlay
final overlayState = Overlay.of(context);
overlayState.insert(overlay);
// Wait for user action
final result = await completer.future;
// Remove the overlay
overlay.remove();
return result;
}