VoiceRecorder class

Whatsapp / Telegram-style voice message recorder. Renders an idle mic button that expands into a recording row (timer + waveform + cancel UX) while active. All active states render at intrinsic width, so the widget is safe to place directly in a Row alongside other flex children without giving up bounded constraints.

Recording engine is pluggable via adapterFactory — implement AudioRecorderAdapter against record, flutter_sound, or your preferred package.

On stop, the file is either uploaded via apiUpload + MediaApiService.uploadAudio (and onUploaded called with the response) OR handed off as a path to onRecorded for custom flows.

Inheritance

Constructors

VoiceRecorder({Key? key, required AudioRecorderAdapter adapterFactory(), RecorderMode mode = RecorderMode.holdToRecord, ApiRequest? apiUpload, void onUploaded(dynamic response)?, void onRecorded(String path)?, Duration? maxDuration, Duration minDuration = const Duration(seconds: 1), bool previewBeforeSend = false, AudioPlayerAdapter playerFactory()?, String previewSendLabel = "Send", String previewDiscardLabel = "Discard", Color? accentColor, Color? backgroundColor, IconData micIcon = Icons.mic, IconData stopIcon = Icons.stop, String slideToCancelLabel = "← Slide to cancel", double cancelThreshold = 100})
const

Properties

accentColor → Color?
final
adapterFactory → AudioRecorderAdapter Function()
final
apiUpload → ApiRequest?
Upload destination. Ignored when onRecorded is supplied.
final
backgroundColor → Color?
final
cancelThreshold → double
Pixels of leftward drag in RecorderMode.holdToRecord before the recording is treated as cancelled on release.
final
hashCode → int
The hash code for this object.
no setterinherited
key → Key?
Controls how one widget replaces another widget in the tree.
finalinherited
maxDuration → Duration?
Auto-stops recording at this duration. Null = no cap.
final
micIcon → IconData
final
minDuration → Duration
Recordings shorter than this are rejected (helps catch accidental taps in RecorderMode.holdToRecord).
final
mode → RecorderMode
final
onRecorded → void Function(String path)?
When set, bypasses MediaApiService entirely and hands off the local file path. Caller owns the file after this returns.
final
onUploaded → void Function(dynamic response)?
Fired with the upload response when apiUpload is used.
final
playerFactory → AudioPlayerAdapter Function()?
Factory for the playback adapter used in the preview state. Required when previewBeforeSend is true.
final
previewBeforeSend → bool
Show a preview row (play/scrub/duration + Send/Discard) before the recorded file is uploaded. Requires playerFactory to be supplied.
final
previewDiscardLabel → String
Label for the discard button in preview state.
final
previewSendLabel → String
Label for the send button in preview state.
final
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
slideToCancelLabel → String
final
stopIcon → IconData
final

Methods

createElement() → StatefulElement
Creates a StatefulElement to manage this widget's location in the tree.
inherited
createState() → State<StatefulWidget>
Creates the mutable state for this widget at a given location in the tree.
override
debugDescribeChildren() → List<DiagnosticsNode>
Returns a list of DiagnosticsNode objects describing this node's children.
inherited
debugFillProperties(DiagnosticPropertiesBuilder properties) → void
Add additional properties associated with the node.
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toDiagnosticsNode({String? name, DiagnosticsTreeStyle? style}) → DiagnosticsNode
Returns a debug representation of the object that is used by debugging tools and by DiagnosticsNode.toStringDeep.
inherited
toString({DiagnosticLevel minLevel = DiagnosticLevel.info}) → String
A string representation of this object.
inherited
toStringDeep({String prefixLineOne = '', String? prefixOtherLines, DiagnosticLevel minLevel = DiagnosticLevel.debug, int wrapWidth = 65}) → String
Returns a string representation of this node and its descendants.
inherited
toStringShallow({String joiner = ', ', DiagnosticLevel minLevel = DiagnosticLevel.debug}) → String
Returns a one-line detailed description of the object.
inherited
toStringShort() → String
A short, textual description of this widget.
inherited

Operators

operator ==(Object other) → bool
The equality operator.
inherited