FormMapDropdownField<TValue> constructor
FormMapDropdownField<TValue> ({
- required FormMapDropdownFieldPicker picker,
- FormController<
TValue> ? form, - Key? key,
- FormAffixStyle? prefix,
- FormAffixStyle? suffix,
- String? hintText,
- String? labelText,
- String? emptyErrorText,
- FormStyle? style,
- void onChanged(
- String? value
- FocusNode? focusNode,
- bool keepAlive = true,
- Widget? icon,
- bool expanded = false,
- TValue onSaved(
- String value
- String validator(
- String? value
- String? initialValue,
- 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);
},
);