Prerequisites
- A working Flutter quickstart
- An initialized
NosmaiCameraPreview
Start recording
final nosmai = NosmaiFlutter.instance;
final started = await nosmai.startRecording();
if (!started) {
throw StateError('Recording did not start');
}
Stop and save
final recording = await nosmai.stopRecording();
if (!recording.success || recording.videoPath == null) {
throw StateError(recording.error ?? 'Recording failed');
}
await nosmai.saveVideoToGallery(
recording.videoPath!,
name: 'nosmai-video',
);
stopRecording returns only after the video has been finalized.
Lifecycle rule
Stop recording before switching the camera, navigating away, or disposing the preview. Guard the record button so a second start or stop cannot overlap the first operation.
Verify it worked
Record a short clip with a visible effect, wait for stopRecording, and play the returned file. Confirm the gallery copy only after saving reports success.
Common errors
| Symptom | Cause | Fix |
|---|---|---|
startRecording returns false | The preview is not ready or recording is already active | Wait for processing and guard duplicate record-button taps |
videoPath is null | Native finalization failed | Read recording.error and keep the screen alive until stop completes |