-
-
Notifications
You must be signed in to change notification settings - Fork 562
Expand file tree
/
Copy pathnested_form.dart
More file actions
68 lines (64 loc) · 2.11 KB
/
nested_form.dart
File metadata and controls
68 lines (64 loc) · 2.11 KB
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import 'package:flutter/material.dart';
import 'package:flutter_form_builder/flutter_form_builder.dart';
class NestedForm extends StatefulWidget {
const NestedForm({
Key? key,
}) : super(key: key);
@override
State<NestedForm> createState() => _NestedFormState();
}
class _NestedFormState extends State<NestedForm> {
GlobalKey<FormBuilderState> formKey = GlobalKey<FormBuilderState>();
@override
Widget build(BuildContext context) {
return Column(
children: [
FormBuilder(
key: formKey,
initialValue: const {
'foo': 'foo value0',
'inner': {
'bar': 'bar value1',
'baz': 'baz value2',
'inner2': {
'test': 'test value',
},
}
},
child: Column(
children: [
FormBuilderTextField(name: 'foo'),
Padding(
padding: const EdgeInsets.only(left: 16.0),
child: NestedFormBuilder(
name: 'inner',
child: Column(
children: [
FormBuilderTextField(name: 'bar'),
FormBuilderTextField(name: 'baz'),
Padding(
padding: const EdgeInsets.only(left: 16.0),
child: NestedFormBuilder(
name: 'inner2',
child: FormBuilderTextField(name: 'test'),
),
)
],
)),
)
],
)),
ElevatedButton(
onPressed: () {
final st = formKey.currentState!;
st.saveAndValidate();
final value = st.value;
debugPrint("debug form value $value");
ScaffoldMessenger.of(context)
.showSnackBar(SnackBar(content: Text(value.toString())));
},
child: const Text("Show Value"))
],
);
}
}