TTextField<T extends String?>.scan constructor

TTextField<T extends String?>.scan({
  1. Key? key,
  2. String? label,
  3. String? placeholder = 'Scan or type',
  4. required ValueChanged<String> onScan,
  5. VoidCallback? onCameraTap,
  6. TInputSize? size,
  7. bool autoFocus = true,
  8. bool disabled = false,
  9. String? helperText,
  10. FocusNode? focusNode,
  11. 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);
    },
  );
}