-
Notifications
You must be signed in to change notification settings - Fork 3
/
uploadForm.dart
199 lines (187 loc) · 6.54 KB
/
uploadForm.dart
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
import 'package:flutter/material.dart';
import 'imageUploader.dart';
void main() => runApp(UploadForm());
class UploadForm extends StatelessWidget {
@override
Widget build(BuildContext context) {
final appTitle = 'Car Details';
return MaterialApp(
title: appTitle,
home: Scaffold(
appBar: AppBar(
title: Text(appTitle),
),
body: MyCustomForm(),
),
);
}
}
// Create a Form widget.
class MyCustomForm extends StatefulWidget {
@override
MyCustomFormState createState() {
return MyCustomFormState();
}
}
// Create a corresponding State class.
// This class holds data related to the form.
class MyCustomFormState extends State<MyCustomForm> {
// Create a global key that uniquely identifies the Form widget
// and allows validation of the form.
//
// Note: This is a GlobalKey<FormState>,
// not a GlobalKey<MyCustomFormState>.
final _formKey = GlobalKey<FormState>();
var values = new Map();
MyCustomFormState() {
this.values[String] = String;
}
@override
Widget build(BuildContext context) {
// Build a Form widget using the _formKey created above.
return Container(
color: Colors.grey.shade300,
margin: EdgeInsets.all(8.0),
padding: EdgeInsets.all(8.0),
child: SingleChildScrollView(
child: Form(
key: _formKey,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
//for inputting the car's make
TextFormField(
decoration: InputDecoration(
hintText: 'Please enter a make:',
icon: Icon(Icons.add_circle_outline),
fillColor: Colors.white,
),
validator: MakeFieldValidator.validate,
onSaved: (value) {
values['make'] = value;
},
),
SizedBox(height: 25),
//for inputting the car's model
TextFormField(
decoration: InputDecoration(
hintText: 'Please enter a model:',
icon: Icon(Icons.add_circle_outline),
fillColor: Colors.white,
),
validator: ModelFieldValidator.validate,
onSaved: (value) {
values['model'] = value;
},
),
SizedBox(height: 25),
//for inputting the car's year
TextFormField(
keyboardType: TextInputType.number,
decoration: InputDecoration(
hintText: 'Please enter a year:',
icon: Icon(Icons.add_circle_outline),
fillColor: Colors.white,
),
validator: YearFieldValidator.validate,
onSaved: (value) {
values['year'] = value;
},
),
SizedBox(height: 25),
//for inputting the car's location
TextFormField(
decoration: InputDecoration(
hintText: "Please enter vehicle's location:",
icon: Icon(Icons.add_circle_outline),
fillColor: Colors.white,
),
validator: LocationFieldValidator.validate,
onSaved: (value) {
values['location'] = value;
},
),
SizedBox(height: 25),
//for inputting the car's mileage
TextFormField(
keyboardType: TextInputType.number,
decoration: InputDecoration(
hintText: "Please enter vehicle's mileage:",
icon: Icon(Icons.add_circle_outline),
fillColor: Colors.white,
),
validator: MileageFieldValidator.validate,
onSaved: (value) {
values['mileage'] = value;
},
),
SizedBox(height: 25),
//for inputting the car's price
TextFormField(
keyboardType: TextInputType.number,
decoration: InputDecoration(
hintText: 'Please enter an asking price:',
icon: Icon(Icons.add_circle_outline),
fillColor: Colors.white,
),
validator: PriceFieldValidator.validate,
onSaved: (value) {
values['price'] = value;
},
),
Padding(
padding: const EdgeInsets.symmetric(vertical: 16.0),
child: RaisedButton(
color: Colors.lightBlueAccent,
onPressed: () async {
// Validate returns true if the form is valid, or false
// otherwise.
if (_formKey.currentState.validate()) {
// If the form is valid, display a Snackbar.
Scaffold.of(context).showSnackBar(
SnackBar(content: Text('Processing Data')));
await new Future.delayed(const Duration(seconds: 2));
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => ImageUploader()));
}
},
child: Text('Submit'),
),
),
],
),
)));
}
}
class MakeFieldValidator {
static String validate(String value) {
return value.isEmpty ? 'Please enter a make:' : null;
}
}
class ModelFieldValidator {
static String validate(String value) {
return value.isEmpty ? 'Please enter a model:' : null;
}
}
class YearFieldValidator {
static String validate(String value) {
return value.isEmpty ? 'Please enter a year:' : null;
}
}
class LocationFieldValidator {
static String validate(String value) {
return value.isEmpty ? "Please enter vehicle's location:" : null;
}
}
class MileageFieldValidator {
static String validate(String value) {
return value.isEmpty ? "Please enter vehicle's mileage:" : null;
}
}
class PriceFieldValidator {
static String validate(String value) {
return value.isEmpty ? 'Please enter an asking price:' : null;
}
}