FormMapDropdownField<TValue> constructor

FormMapDropdownField<TValue>({
  1. required FormMapDropdownFieldPicker picker,
  2. FormController<TValue>? form,
  3. Key? key,
  4. FormAffixStyle? prefix,
  5. FormAffixStyle? suffix,
  6. String? hintText,
  7. String? labelText,
  8. String? emptyErrorText,
  9. FormStyle? style,
  10. void onChanged(
    1. String? value
    )?,
  11. FocusNode? focusNode,
  12. bool keepAlive = true,
  13. Widget? icon,
  14. bool expanded = false,
  15. TValue onSaved(
    1. String value
    )?,
  16. String validator(
    1. String? value
    )?,
  17. String? initialValue,
  18. bool enabled = true,
})

Drop down form to select from there with Map as an option.

A form field that allows you to select Key-Value pair Map format data from a dropdown menu. Common design can be applied with FormStyle, and selection state can be managed using FormController.

Key-ValueペアのMap形式のデータをドロップダウンメニューで選択できるフォームフィールド。 FormStyleで共通したデザインを適用可能。またFormControllerを利用することで選択状態を管理できます。

Basic Usage Example 基本的な使用例

final countries = <String, String>{
  "ja": "日本語",
  "en": "English",
  "es": "Español",
  "fr": "Français",
};

FormMapDropdownField(
  form: formController,
  initialValue: formController.value.selectedLanguage,
  onSaved: (value) => formController.value.copyWith(selectedLanguage: value),
  picker: FormMapDropdownFieldPicker(
    values: countries,
  ),
);

Usage Example with Validation バリデーション付きの使用例

FormMapDropdownField(
  form: formController,
  initialValue: formController.value.selectedLanguage,
  onSaved: (value) => formController.value.copyWith(selectedLanguage: value),
  validator: (value) {
    if (value == null) {
      return "地域を選択してください";
    }
    return null;
  },
  picker: FormMapDropdownFieldPicker(
    values: countries,
  ),
);

Implementation

FormMapDropdownField({
  required this.picker,
  this.form,
  super.key,
  this.prefix,
  this.suffix,
  this.hintText,
  this.labelText,
  this.emptyErrorText,
  this.style,
  this.onChanged,
  this.focusNode,
  this.keepAlive = true,
  this.icon,
  this.expanded = false,
  TValue Function(String value)? onSaved,
  String Function(String? value)? validator,
  super.initialValue,
  super.enabled,
})  : 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 == null) {
            return emptyErrorText;
          }
          return validator?.call(value);
        },
      );