Skip to content

Commit eed59db

Browse files
committed
fix
1 parent b766c93 commit eed59db

21 files changed

+1973
-55
lines changed

CHANGELOG.md

+17-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
11
## 0.0.1
2+
* new flutter form.
23

3-
* TODO: Describe initial release.
4+
## 0.1.1
5+
* add list animation
6+
* add list divider
7+
* add textfield config
8+
9+
## 0.2.0
10+
* add clearButtonMode
11+
* add obscureText
12+
* add keyboardType
13+
14+
## 0.3.0
15+
* add dynamic form example
16+
* bug fix
17+
18+
## 0.4.0
19+
* bug fix

LICENSE

+21-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,21 @@
1-
TODO: Add your license here.
1+
MIT License
2+
3+
Copyright (c) 2020 yichahucha
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

+13-9
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
11
# tform
22

3-
A new flutter plugin project.
3+
A easy, extensible and dynamic flutter form framework.
44

5-
## Getting Started
5+
## Installing
6+
Add this to your package's pubspec.yaml file:
7+
```yaml
8+
dependencies:
9+
tform: ^0.4.0
10+
```
611
7-
This project is a starting point for a Flutter
8-
[plug-in package](https://flutter.dev/developing-packages/),
9-
a specialized package that includes platform-specific implementation code for
10-
Android and/or iOS.
12+
## Example
13+
![avatar](./raw/demo.gif)
1114
12-
For help getting started with Flutter, view our
13-
[online documentation](https://flutter.dev/docs), which offers tutorials,
14-
samples, guidance on mobile development, and a full API reference.
15+
## Build Form Rows
16+
![avatar](./raw/carbon_rows.png)
1517
18+
## Build Form
19+
![avatar](./raw/carbon_page.png)

example/lib/application.dart

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import 'package:flutter/material.dart';
2+
3+
class Application {
4+
static BuildContext appContext;
5+
}

example/lib/basic/form_page.dart

+158
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
import 'package:flutter/cupertino.dart';
2+
import 'package:flutter/material.dart';
3+
import 'package:tform/form/form.dart';
4+
5+
import 'package:tform/tform.dart';
6+
7+
import '../utils.dart';
8+
9+
import 'package:tform_example/widgets/photos_cell.dart';
10+
import 'package:tform_example/widgets/verifitionc_code_button.dart';
11+
12+
class FormPage extends StatelessWidget {
13+
FormPage({Key key}) : super(key: key);
14+
final GlobalKey _formKey = GlobalKey<TFormState>();
15+
16+
@override
17+
Widget build(BuildContext context) {
18+
return Scaffold(
19+
appBar: AppBar(
20+
title: Text("表单"),
21+
actions: [
22+
FlatButton(
23+
child: Text(
24+
"提交",
25+
style: TextStyle(color: Colors.white, fontSize: 16),
26+
),
27+
onPressed: () {
28+
//校验
29+
List errors = (_formKey.currentState as TFormState).validate();
30+
if (errors.length > 0) {
31+
showToast(errors.first);
32+
return;
33+
}
34+
//通过
35+
showToast("提交成功");
36+
},
37+
),
38+
],
39+
),
40+
body: TForm.builder(
41+
key: _formKey,
42+
rows: buildFormRows(),
43+
readOnly: false,
44+
divider: Divider(
45+
height: 0.5,
46+
thickness: 0.5,
47+
),
48+
),
49+
);
50+
}
51+
}
52+
53+
List<TFormRow> buildFormRows() {
54+
return [
55+
TFormRow.input(
56+
enabled: false,
57+
title: "姓名",
58+
placeholder: "请输入姓名",
59+
value: "张二蛋",
60+
fieldConfig: TFormFieldConfig(
61+
height: 100, style: TextStyle(color: Colors.red, fontSize: 20)),
62+
),
63+
TFormRow.input(
64+
title: "身份证号",
65+
placeholder: "请输入身份证号",
66+
value: "4101041991892382938293",
67+
clearButtonMode: OverlayVisibilityMode.editing,
68+
),
69+
TFormRow.input(
70+
keyboardType: TextInputType.number,
71+
title: "预留手机号",
72+
placeholder: "请输入手机号",
73+
maxLength: 11,
74+
requireMsg: "请输入正确的手机号",
75+
requireStar: true,
76+
validator: (row) {
77+
return RegExp(
78+
r'^((13[0-9])|(14[0-9])|(15[0-9])|(16[0-9])|(17[0-9])|(18[0-9])|(19[0-9]))\d{8}$')
79+
.hasMatch(row.value);
80+
},
81+
),
82+
TFormRow.input(
83+
title: "验证码",
84+
placeholder: "请输入验证码",
85+
suffixWidget: (context, row) {
86+
return VerifitionCodeButton(
87+
title: "获取验证码",
88+
seconds: 60,
89+
onPressed: () {
90+
showToast("验证码已发送");
91+
},
92+
);
93+
},
94+
),
95+
TFormRow.selector(
96+
title: "学历",
97+
placeholder: "请选择",
98+
options: ["小学", "初中", "高中", "专科", "本科", "硕士及以上"],
99+
),
100+
TFormRow.multipleSelector(
101+
title: "家庭成员",
102+
placeholder: "请选择",
103+
options: ["父亲", "母亲", "女儿", "儿子"],
104+
),
105+
TFormRow.customSelector(
106+
title: "婚姻状况",
107+
placeholder: "请选择",
108+
state: [
109+
["未婚", "已婚"],
110+
[
111+
TFormRow.input(
112+
title: "配偶姓名", placeholder: "请输入配偶姓名", requireStar: true),
113+
TFormRow.input(
114+
title: "配偶电话", placeholder: "请输入配偶电话", requireStar: true)
115+
]
116+
],
117+
onTap: (context, row) async {
118+
String value = await showPicker(row.state[0], context);
119+
if (value == "已婚") {
120+
TForm.of(context).insert(row, row.state[1]);
121+
} else {
122+
TForm.of(context).delete(row.state[1]);
123+
}
124+
return value;
125+
},
126+
),
127+
TFormRow.customSelector(
128+
title: "出生年月",
129+
placeholder: "请选择",
130+
onTap: (context, row) async {
131+
return showPickerDate(context);
132+
},
133+
),
134+
TFormRow.customCell(
135+
widget: Container(
136+
color: Colors.grey[200],
137+
height: 48,
138+
width: double.infinity,
139+
alignment: Alignment.center,
140+
child: Text("------ 我是自定义的Cell ------")),
141+
),
142+
TFormRow.customCellBuilder(
143+
title: "房屋照片",
144+
state: [
145+
{"picurl": ""},
146+
{"picurl": ""},
147+
{"picurl": ""}
148+
],
149+
requireMsg: "请完成上传房屋照片",
150+
validator: (row) {
151+
return row.state.every((element) => (element["picurl"].length > 0));
152+
},
153+
widgetBuilder: (context, row) {
154+
return CustomPhotosWidget(row: row);
155+
},
156+
),
157+
];
158+
}

0 commit comments

Comments
 (0)