TTextField<T extends String?>.scan constructor
TTextField<T extends String?>.scan ({
- Key? key,
- String? label,
- String? placeholder = 'Scan or type',
- required ValueChanged<
String> onScan, - VoidCallback? onCameraTap,
- TInputSize? size,
- bool autoFocus = true,
- bool disabled = false,
- String? helperText,
- FocusNode? focusNode,
- TextEditingController? textController,
Creates a scan-first input for handheld workflows.
A hardware (keyboard-wedge) scanner types the barcode and sends Enter;
that fires onScan with the scanned text, clears the field and keeps
focus ready for the next scan. onCameraTap adds a camera scan button.
Implementation
factory TTextField.scan({
Key? key,
String? label,
String? placeholder = 'Scan or type',
required ValueChanged<String> onScan,
VoidCallback? onCameraTap,
TInputSize? size,
bool autoFocus = true,
bool disabled = false,
String? helperText,
FocusNode? focusNode,
TextEditingController? textController,
}) {
return TTextField<T>(
key: key,
label: label,
placeholder: placeholder,
helperText: helperText,
size: size,
autoFocus: autoFocus,
disabled: disabled,
focusNode: focusNode,
textController: textController,
textInputAction: TextInputAction.done,
selectAllOnFocus: true,
clearOnSubmit: true,
keepFocusOnSubmit: true,
postWidget: onCameraTap == null
? null
: IconButton(
tooltip: 'Scan with camera',
constraints: const BoxConstraints(minWidth: 48, minHeight: 48),
icon: const Icon(Icons.qr_code_scanner_rounded),
onPressed: disabled ? null : onCameraTap,
),
onSubmitted: (text) {
final trimmed = text.trim();
if (trimmed.isNotEmpty) onScan(trimmed);
},
);
}