ListField<T> constructor
ListField<T> ({
- Widget? getLeading(
- BuildContext context,
- T model
- Widget? getTitle(
- BuildContext context,
- T model
- Widget? getSubtitle(
- BuildContext context,
- T model
- double height = 250,
- String? labelPrefix,
- String? label,
- Widget? labelWidget,
- ListFieldController<
T> ? controller, - FormFieldValidator<
List< ? validator,T> ?> - FormFieldSetter<
List< ? onSaved,T> > - List<
T> ? initialValue, - bool enabled = true,
- AutovalidateMode autoValidateMode = AutovalidateMode.disabled,
- bool filled = false,
- Color? fillColor,
- Color? focusColor,
- InputDecoration? decoration,
- EdgeInsets padding = const EdgeInsets.all(8),
- String? hintText,
- EdgeInsets? contentPadding,
- bool showAddButton = true,
- IconData addButtonIcon = FontAwesomeIcons.plus,
- String? addButtonEntity,
- String addButtonMessage = 'Adicionar %s',
- Future<
List< addButtonOnTap(T> ?>- BuildContext context,
- List<
T> data
- bool canDelete(
- T model
- IconData deleteIcon = FontAwesomeIcons.trashCan,
- int? sizeExtraSmall,
- int? sizeSmall,
- int? sizeMedium,
- int? sizeLarge,
- int? sizeExtraLarge,
- double? minHeight,
- Key? key,
Implementation
ListField({
this.getLeading,
this.getTitle,
this.getSubtitle,
final double height = 250,
final String? labelPrefix,
final String? label,
final Widget? labelWidget,
this.controller,
final FormFieldValidator<List<T>?>? validator,
super.onSaved,
final List<T>? initialValue,
super.enabled,
final AutovalidateMode autoValidateMode = AutovalidateMode.disabled,
final bool filled = false,
final Color? fillColor,
final Color? focusColor,
final InputDecoration? decoration,
final EdgeInsets padding = const EdgeInsets.all(8),
final String? hintText,
final EdgeInsets? contentPadding,
final bool showAddButton = true,
this.addButtonIcon = FontAwesomeIcons.plus,
this.addButtonEntity,
this.addButtonMessage = 'Adicionar %s',
this.addButtonOnTap,
this.canDelete,
this.deleteIcon = FontAwesomeIcons.trashCan,
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,
autovalidateMode: autoValidateMode,
builder: (final FormFieldState<List<T>?> field) {
final _ListFieldState<T> state = field as _ListFieldState<T>;
final InputDecoration effectiveDecoration =
(decoration ??
InputDecoration(
border: const OutlineInputBorder(),
filled: filled,
fillColor: fillColor,
label: labelWidget,
labelText: <String?>[
labelPrefix,
label,
].nonNulls.join(' - '),
counterText: '',
focusColor: focusColor,
hintText: hintText,
contentPadding: contentPadding,
// prefix: prefix,
// suffix: suffix,
))
.applyDefaults(Theme.of(field.context).inputDecorationTheme);
return SizedBox(
height: height,
child: Padding(
padding: padding,
child: InputDecorator(
decoration: effectiveDecoration.copyWith(
errorText: enabled ? field.errorText : null,
enabled: enabled,
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
// Add Button
if (showAddButton) _ListAddButton<T>(state),
// List
Expanded(
child: ValueListenableBuilder<List<T>>(
valueListenable: state._effectiveController,
builder: (_, final List<T> value, _) => Column(
children: <Widget>[
if (showAddButton && value.isNotEmpty)
const Divider(),
Expanded(child: _ListBuilder<T>(state, value)),
],
),
),
),
],
),
),
),
);
},
);