FormChipsField<TValue> constructor

FormChipsField<TValue>({
  1. Key? key,
  2. FormController<TValue>? form,
  3. FormStyle? style,
  4. bool enabled = true,
  5. String? hintText,
  6. String? labelText,
  7. FormAffixStyle? prefix,
  8. FormAffixStyle? suffix,
  9. bool readOnly = false,
  10. required ChipBuilder<String> builder,
  11. ChipBuilder<String>? suggestionBuilder,
  12. List<String> suggestion = const [],
  13. void onChanged(
    1. List<String>? value
    )?,
  14. void onChipTapped(
    1. String value
    )?,
  15. int? maxChips,
  16. String? emptyErrorText,
  17. FocusNode? focusNode,
  18. TextInputType keyboardType = TextInputType.text,
  19. bool obscureText = false,
  20. SuggestionStyle? suggestionStyle,
  21. bool keepAlive = true,
  22. TValue onSaved(
    1. List<String> value
    )?,
  23. String validator(
    1. List<String>? value
    )?,
  24. List<String> initialValue = const [],
})

Implementation

FormChipsField({
  super.key,
  this.form,
  this.style,
  super.enabled,
  this.hintText,
  this.labelText,
  this.prefix,
  this.suffix,
  this.readOnly = false,
  required ChipBuilder<String> builder,
  this.suggestionBuilder,
  this.suggestion = const [],
  this.onChanged,
  this.onChipTapped,
  this.maxChips,
  this.emptyErrorText,
  this.focusNode,
  this.keyboardType = TextInputType.text,
  this.obscureText = false,
  this.suggestionStyle,
  this.keepAlive = true,
  TValue Function(List<String> value)? onSaved,
  String Function(List<String>? value)? validator,
  List<String> super.initialValue = const [],
})  : _builder = builder,
      assert(
        (form == null && onSaved == null) ||
            (form != null && onSaved != null),
        "Both are required when using [form] or [onSaved].",
      ),
      super(
        builder: (state) {
          return const SizedBox.shrink();
        },
        onSaved: (value) {
          if (value == null) {
            return;
          }
          final res = onSaved?.call(value);
          if (res == null) {
            return;
          }
          form!.value = res;
        },
        validator: (value) {
          if (emptyErrorText.isNotEmpty && value.isEmpty) {
            return emptyErrorText;
          }
          return validator?.call(value);
        },
      );