1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
| 场景:如企业审批、教育作业、医疗表单等都可通过表单模板 + Redux 动态驱动页面。
1、表单 JSON 配置 { "formId": "job_application", "fields": [ {"type": "text", "label": "姓名", "key": "name"}, {"type": "dropdown", "label": "学历", "key": "degree", "options": ["本科", "硕士"]}, {"type": "file", "label": "简历附件", "key": "resume"} ] }
2、Redux 中状态设计
class FormState { final String formId; final Map<String, dynamic> values; final Map<String, String> validationErrors; }
动态构建表单 UI: StoreConnector<AppState, FormState>( converter: (store) => store.state.form, builder: (context, formState) { return DynamicFormBuilder(config, formState); }, )
通过 UpdateFormFieldAction 动态更新状态,自动完成状态收集和提交逻辑。
|