深色模式
Flutter处理表单
官方库
使用SDK内置的Form
、TextFormField
等,优点是不必引入第三方库,缺点是使用有点繁琐,不适合处理大量表单页面的情况。
如果需要处理大量表单,可以使用第三方库。
第三方库
常规表单
可以使用flutter_form_builder,能避免写很多重复的代码,它内置了常规的表单类型:
FormBuilderCheckbox
- Single checkbox fieldFormBuilderCheckboxGroup
- List of checkboxes for multiple selectionFormBuilderChoiceChip
- Creates a chip that acts like a radio button.FormBuilderDateRangePicker
- For selection of a range of datesFormBuilderDateTimePicker
- For Date, Time and DateTime inputFormBuilderDropdown
- Used to select one value from a list as a DropdownFormBuilderFilterChip
- Creates a chip that acts like a checkboxFormBuilderRadioGroup
- Used to select one value from a list of Radio WidgetsFormBuilderRangeSlider
- Used to select a range from a range of valuesFormBuilderSlider
- For selection of a numerical value on a sliderFormBuilderSwitch
- On/Off switch fieldFormBuilderTextField
- A Material Design text field input
表单验证
建议使用与之配套的表单验证规则库:form_builder_validators
非常规表单
在以上常规表单类型之外,还有:
选取文件的表单form_builder_file_picker
选取图片的表单form_builder_image_picker
还有不常用但很炫的form_builder_extra_fields,其中包含:
FormBuilderColorPicker
- Input for Color selectionFormBuilderRating
- For selection of a numerical value as a ratingFormBuilderSearchableDropdown
- Field for selecting value(s) from a searchable listFormBuilderSignaturePad
- Field with drawing pad on which user can doodleFormBuilderTouchSpin
- Selection of a number by tapping on a plus or minus iconFormBuilderTypeAhead
- Auto-completes user input from a list of items
以上都是同一个开发者的开源项目。