ListField<T> constructor

ListField<T>({
  1. Widget? getLeading(
    1. BuildContext context,
    2. T model
    )?,
  2. Widget? getTitle(
    1. BuildContext context,
    2. T model
    )?,
  3. Widget? getSubtitle(
    1. BuildContext context,
    2. T model
    )?,
  4. double height = 250,
  5. String? labelPrefix,
  6. String? label,
  7. Widget? labelWidget,
  8. ListFieldController<T>? controller,
  9. FormFieldValidator<List<T>?>? validator,
  10. FormFieldSetter<List<T>>? onSaved,
  11. List<T>? initialValue,
  12. bool enabled = true,
  13. AutovalidateMode autoValidateMode = AutovalidateMode.disabled,
  14. bool filled = false,
  15. Color? fillColor,
  16. Color? focusColor,
  17. InputDecoration? decoration,
  18. EdgeInsets padding = const EdgeInsets.all(8),
  19. String? hintText,
  20. EdgeInsets? contentPadding,
  21. bool showAddButton = true,
  22. IconData addButtonIcon = FontAwesomeIcons.plus,
  23. String? addButtonEntity,
  24. String addButtonMessage = 'Adicionar %s',
  25. Future<List<T>?> addButtonOnTap(
    1. BuildContext context,
    2. List<T> data
    )?,
  26. bool canDelete(
    1. T model
    )?,
  27. IconData deleteIcon = FontAwesomeIcons.trashCan,
  28. int? sizeExtraSmall,
  29. int? sizeSmall,
  30. int? sizeMedium,
  31. int? sizeLarge,
  32. int? sizeExtraLarge,
  33. double? minHeight,
  34. 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)),
                         ],
                       ),
                     ),
                   ),
                 ],
               ),
             ),
           ),
         );
       },
     );