ec_form 1.1.3
ec_form: ^1.1.3 copied to clipboard
一个flutter表单组件,主要用于处理表单提交业务。
import 'package:flutter/material.dart';
import 'package:ec_form/ec_form.dart';
import 'package:flutter/services.dart';
void main() {
SystemChrome.setSystemUIOverlayStyle(
SystemUiOverlayStyle.light.copyWith(statusBarColor: Colors.transparent),
);
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(primarySwatch: Colors.blue),
home: _ECFormDemoPage(),
);
}
}
// ignore: must_be_immutable
class _ECFormDemoPage extends ECFormBasePage {
_ECFormDemoPageVM vm = _ECFormDemoPageVM();
@override
String? get title => "表单提交";
@override
Widget? get leading => Container();
@override
Widget? get bottomWidget =>
TextButton(onPressed: vm.commit, child: const Text("提交"));
@override
ECFormBasePageVM get pageVM => vm;
@override
setup(BuildContext context) {
vm.loadData();
return super.setup(context);
}
}
class _ECFormDemoPageVM extends ECFormBasePageVM {
/// 配置cell vm
loadData() {
datas.addAll([
// 输入
ECFormInputWidgetVM(
paramKey: 'name',
value: "不可修改名字",
title: '名字',
enable: false,
),
ECFormInputWidgetVM(
paramKey: 'name1',
title: '名字',
checkCall: (out) => out.length >= 2,
errorString: "至少输入2个字",
),
// 日期
ECFormDateSelectWidgetVM(paramKey: 'startDate', title: "出发时间"),
ECFormDateSelectWidgetVM(paramKey: 'endDate', title: "到达时间"),
// 选择
ECFormInputSelectWidgetVM(
paramKey: 'cardId',
title: "车子",
selectList: [
ECFormInputSelectItem(name: "宝马", value: "475993"),
ECFormInputSelectItem(name: "奔驰", value: "976979"),
],
),
// 选择(带单位)
ECFormInputSelectUnitWidgetVM(
paramKey: 'cardWight',
title: "车子重",
keyboardType: TextInputType.number,
selectedItem: ECFormInputSelectItem(name: "吨", value: "1"),
),
// 选择(带可选择单位)
ECFormInputSelectUnitWidgetVM(
paramKey: 'cardWight1',
unitParamKey: "unitCode",
title: "重量",
selectedItem: ECFormInputSelectItem(name: "吨", value: "1"),
unitCanSelect: true,
keyboardType: TextInputType.number,
unitSelectList: [
ECFormInputSelectItem(name: "吨", value: "1"),
ECFormInputSelectItem(name: "千克", value: "2"),
],
),
// 备注
ECFormRemarkWidgetVM(
title: "添加备注",
paramKey: 'remark',
height: 100,
maxLength: 50,
),
// 自定义选择
ECFormInputSelectCustomizeWidgetVM(
paramKey: "customize",
title: "自定义选择",
didClick: (p0) {
debugPrint("点击了自定义选择");
},
),
// 开关
ECFormSwitchWidgetVM(title: "是否同意协议", paramKey: "isAgree", value: "1"),
// 展示
ECFormSectionTitleWidgetVM(title: "大标题"),
// 展示Table案例
ECFormTableCellVM(
title: "展示Table案例",
subTitle: "我是子标题",
titles: ["标题1", "标题2", "标题3"],
rows: [
ECTableRow([
ECTableRowItem(title: "row1-1"),
ECTableRowItem(title: "row1-2"),
ECTableRowItem(title: "row1-3"),
]),
ECTableRow([
ECTableRowItem(title: "row2-1"),
ECTableRowItem(title: "row2-2"),
ECTableRowItem(title: "row2-3"),
]),
],
),
]);
update();
}
commit() {
if (!check()) return;
// 收集的参数param
Map<String, dynamic> param = getParam();
debugPrint("收集的参数: ${param.toString()}");
}
}