ListField<T> constructor
ListField<T> ({
- ListFieldController<
T> ? controller, - FocusNode? focusNode,
- Widget? getLeading(
- BuildContext context,
- T model, {
- required bool enabled,
- Widget? getTitle(
- BuildContext context,
- T model, {
- required bool enabled,
- Widget? getSubtitle(
- BuildContext context,
- T model, {
- required bool enabled,
- String? labelPrefix,
- String? label,
- Widget? labelWidget,
- FormFieldValidator<
List< ? validator,T> ?> - FormFieldSetter<
List< ? onSaved,T> > - List<
T> ? initialValue, - bool enabled = true,
- AutovalidateMode? autovalidateMode = AutovalidateMode.disabled,
- InputDecoration? decoration,
- EdgeInsets padding = const EdgeInsets.all(8),
- EdgeInsets? contentPadding,
- bool showAddButton = true,
- IconData addButtonIcon = FontAwesomeIcons.plus,
- String addButtonLabel = 'Adicionar',
- Future<
List< addButtonOnTap(T> ?>- BuildContext context,
- List<
T> data
- bool canDelete(
- T model
- IconData deleteIcon = FontAwesomeIcons.trashCan,
- String deleteMessage(
- BuildContext context,
- T model
- String deleteDefaultMessage = 'Deseja excluir o ítem?',
- Future<
T?> itemOnTap(- BuildContext context,
- T model
- int? sizeExtraSmall,
- int? sizeSmall,
- int? sizeMedium,
- int? sizeLarge,
- int? sizeExtraLarge,
- double? minHeight,
- Key? key,
Implementation
ListField({
this.controller,
this.focusNode,
this.getLeading,
this.getTitle,
this.getSubtitle,
String? labelPrefix,
String? label,
Widget? labelWidget,
FormFieldValidator<List<T>?>? validator,
super.onSaved,
List<T>? initialValue,
super.enabled,
super.autovalidateMode = AutovalidateMode.disabled,
InputDecoration? decoration,
EdgeInsets padding = const EdgeInsets.all(8),
EdgeInsets? contentPadding,
bool showAddButton = true,
this.addButtonIcon = FontAwesomeIcons.plus,
this.addButtonLabel = 'Adicionar',
this.addButtonOnTap,
this.canDelete,
this.deleteIcon = FontAwesomeIcons.trashCan,
this.deleteMessage,
this.deleteDefaultMessage = 'Deseja excluir o ítem?',
this.itemOnTap,
super.sizeExtraSmall,
super.sizeSmall,
super.sizeMedium,
super.sizeLarge,
super.sizeExtraLarge,
super.minHeight,
super.key,
}) : assert(
initialValue == null || controller == null,
'initialValue or controller must be null.',
),
assert(
label == null || labelWidget == null,
'label or labelWidget must be null.',
),
super(
initialValue: controller != null ? controller.value : initialValue,
validator: enabled ? validator : null,
builder: (FormFieldState<List<T>?> field) {
final _ListFieldState<T> state = field as _ListFieldState<T>;
final ThemeData theme = Theme.of(state.context);
final bool hasFocus = state._effectiveFocusNode.hasFocus;
final InputDecoration effectiveDecoration =
(decoration ??
InputDecoration(
border: const OutlineInputBorder(),
counterText: '',
label: labelWidget,
labelText: <String?>[
labelPrefix,
label,
].nonNulls.join(' - '),
contentPadding: contentPadding,
))
.applyDefaults(theme.inputDecorationTheme)
.copyWith(enabled: enabled, errorText: state.errorText);
return Padding(
padding: padding,
child: Focus(
focusNode: state._effectiveFocusNode,
canRequestFocus: enabled,
skipTraversal: !enabled,
child: MouseRegion(
cursor: enabled
? SystemMouseCursors.click
: SystemMouseCursors.basic,
onEnter: (_) => state.hovering(enter: true),
onExit: (_) => state.hovering(enter: false),
child: InputDecorator(
decoration: effectiveDecoration,
isFocused: hasFocus,
isHovering: state._isHovering,
child: ValueListenableBuilder<List<T>>(
valueListenable: state._effectiveController,
builder: (_, List<T> value, _) {
return Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
/// Add Button
if (showAddButton)
_ListAddButton<T>(state, enabled: enabled),
/// List Items
...value.map(
(T model) => _ListItem<T>(
context: state.context,
widget: state.widget,
focusNode: state._effectiveFocusNode,
model: model,
enabled: enabled,
onRemove: (T model) =>
state.didChange(state.value?..remove(model)),
onTap: state.widget.itemOnTap == null
? null
: (T model) async {
final T? newModel = await state
.widget
.itemOnTap
?.call(state.context, model);
if (newModel == null) return;
state.didChange(state.value);
},
),
),
].intersperse(const Divider()),
);
},
),
),
),
),
);
},
);