-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathform_example.dart
More file actions
228 lines (211 loc) · 7.57 KB
/
form_example.dart
File metadata and controls
228 lines (211 loc) · 7.57 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
// SPDX-FileCopyrightText: 2022 Iconica
//
// SPDX-License-Identifier: BSD-3-Clause
import 'package:flutter/material.dart';
import 'package:flutter_form_wizard/flutter_form.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:form_example/example_pages/age_page.dart';
import 'package:form_example/example_pages/carousel_page.dart';
import 'package:form_example/example_pages/check_page.dart';
import 'package:form_example/example_pages/name_page.dart';
import 'package:intl/intl.dart';
import 'example_pages/date_page.dart';
class FormExample extends ConsumerStatefulWidget {
const FormExample({Key? key}) : super(key: key);
@override
ConsumerState<ConsumerStatefulWidget> createState() => _FormExampleState();
}
class _FormExampleState extends ConsumerState<FormExample> {
final FlutterFormController formController = FlutterFormController();
final String checkPageText = "All entered info: ";
final phoneInputController = FlutterFormInputPhoneController(
id: 'phone',
onChanged: (value) {
debugPrint(
'${value?.dialCode ?? 'no dial'} ${value?.number ?? 'no number'}');
},
);
final ageInputController = FlutterFormInputNumberPickerController(
id: "age",
checkPageTitle: (dynamic amount) {
return "Age: $amount years";
},
onChanged: (value) => debugPrint(value.toString()),
);
late final FlutterFormInputCarouselController carouselInputController;
final List<Map<String, dynamic>> cars = [
{
"title": "Mercedes",
"description": "Mercedes is a car",
},
{
"title": "BMW",
"description": "BMW is a car",
},
{
"title": "Mazda",
'description': "Mazda is a car",
},
];
FlutterFormInputPlainTextController firstNameController =
FlutterFormInputPlainTextController(
mandatory: true,
id: "firstName",
checkPageTitle: (dynamic firstName) {
return "First Name: $firstName";
},
onChanged: (value) => debugPrint(value),
);
FlutterFormInputPlainTextController lastNameController =
FlutterFormInputPlainTextController(
mandatory: true,
id: "lastName",
checkPageTitle: (dynamic lastName) {
return "Last Name: $lastName";
},
onChanged: (value) => debugPrint(value),
);
FlutterFormInputDateTimeController dateController =
FlutterFormInputDateTimeController(
id: "date",
dateTimeType: FlutterFormDateTimeType.date,
dateFormat: DateFormat('dd-MM-yyyy'),
checkPageTitle: (dynamic date) => "Date: $date",
onChanged: (String? value) => () {
debugPrint(value.toString());
},
value: DateTime.now().toString(),
);
@override
void initState() {
super.initState();
carouselInputController = FlutterFormInputCarouselController(
id: 'carCarousel',
checkPageTitle: (dynamic index) {
return cars[index]["title"];
},
checkPageDescription: (dynamic index) {
return cars[index]["description"];
},
onChanged: (value) => debugPrint(value.toString()),
);
}
bool showLastName = true;
@override
Widget build(BuildContext context) {
var size = MediaQuery.of(context).size;
var fontSize = size.height / 40;
return GestureDetector(
onTap: () => FocusScope.of(context).unfocus(),
child: Scaffold(
body: Center(
child: FlutterForm(
formController: formController,
options: FlutterFormOptions(
onFinished: (Map<int, Map<String, dynamic>> results) {
debugPrint("Final full results: $results");
Navigator.of(context).pushReplacementNamed('/thanks');
},
onNext: (int pageNumber, Map<String, dynamic> results) {
debugPrint("Results page $pageNumber: $results");
},
nextButton: (int pageNumber, bool checkingPages) {
return Align(
alignment: Alignment.bottomCenter,
child: Padding(
padding: EdgeInsets.only(
bottom: size.height * 0.05,
),
child: SizedBox(
height: size.height * 0.07,
width: size.width * 0.7,
child: ElevatedButton(
style: ElevatedButton.styleFrom(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(5),
),
backgroundColor: Colors.black,
textStyle: TextStyle(
fontSize: fontSize,
fontWeight: FontWeight.w600,
color: Colors.white,
),
),
onPressed: () async {
await formController.autoNextStep();
},
child: Text(checkingPages ? "Save" : "Next Page"),
),
),
),
);
},
backButton: (int pageNumber, bool checkingPages, int pageAmount) {
if (pageNumber != 0) {
if (!checkingPages || pageNumber >= pageAmount) {
return Align(
alignment: Alignment.topLeft,
child: Container(
margin: EdgeInsets.only(
top: size.height * 0.045,
left: size.width * 0.07,
),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(90),
color: const Color(0xFFD8D8D8).withOpacity(0.50),
),
child: IconButton(
padding: EdgeInsets.zero,
splashRadius: size.width * 0.06,
onPressed: () {
formController.previousStep();
},
icon: const Icon(Icons.chevron_left),
)),
);
}
}
return Container();
},
pages: [
FlutterFormPage(
child: Center(
child: FlutterFormInputPhone(
controller: phoneInputController,
validationMessage: 'Please fill in a valid phone number',
),
),
),
FlutterFormPage(
child: AgePage(
inputController: ageInputController,
),
),
FlutterFormPage(
child: NamePage(
firstNameController: firstNameController,
lastNameController: lastNameController,
showLastName: showLastName,
),
),
FlutterFormPage(
child: CarouselPage(
inputController: carouselInputController,
cars: cars,
),
),
FlutterFormPage(
child: DatePage(
dateController: dateController,
),
),
],
checkPage: CheckPageExample()
.showCheckpage(context, size, fontSize, checkPageText),
),
),
),
),
);
}
}