@@ -129,89 +129,96 @@ class _PitScoutingState extends State<PitScoutingPage> {
129129 ),
130130 body: ListView .builder (
131131 padding: const EdgeInsets .all (8 ),
132- itemCount: formFields['Pit' ]? .length ?? 0 ,
132+ itemCount: formFields['Pit' ]? .length + 1 ?? 0 ,
133133 itemBuilder: (BuildContext context, int index) {
134- var field = formFields['Pit' ][index];
135- bool showError = fieldErrors[field['name' ]] ?? false ;
136- if (field['type' ] == 'number' ) {
137- return Column (
138- children: [
139- TextFormField (
140- keyboardType: TextInputType .number,
141- initialValue:
142- textValues[field['name' ]] ?? '' , // Use the stored value
143- decoration: InputDecoration (
144- labelText: field['name' ],
145- errorText: showError ? 'This field is required' : null ,
146- ),
147- onChanged: (value) {
148- if (field['required' ] && (value == null || value.isEmpty)) {
149- fieldErrors[field['name' ]] = true ;
150- } else {
151- fieldErrors[field['name' ]] = false ;
152- }
153- textValues[field['name' ]] = value; // Update textValues
154- setState (() {});
155- },
156- ),
157- ],
158- );
159- } else if (field['type' ] == 'text' ) {
160- return Column (
161- children: [
162- TextFormField (
163- initialValue:
164- textValues[field['name' ]] ?? '' , // Use the stored value
165- decoration: InputDecoration (
166- labelText: field['name' ],
167- errorText: showError ? 'This field is required' : null ,
134+ if (index != formFields['Pit' ]? .length) {
135+ var field = formFields['Pit' ][index];
136+ bool showError = fieldErrors[field['name' ]] ?? false ;
137+ if (field['type' ] == 'number' ) {
138+ return Column (
139+ children: [
140+ TextFormField (
141+ keyboardType: TextInputType .number,
142+ initialValue:
143+ textValues[field['name' ]] ?? '' , // Use the stored value
144+ decoration: InputDecoration (
145+ labelText: field['name' ],
146+ errorText: showError ? 'This field is required' : null ,
147+ ),
148+ onChanged: (value) {
149+ if (field['required' ] &&
150+ (value == null || value.isEmpty)) {
151+ fieldErrors[field['name' ]] = true ;
152+ } else {
153+ fieldErrors[field['name' ]] = false ;
154+ }
155+ textValues[field['name' ]] = value; // Update textValues
156+ setState (() {});
157+ },
168158 ),
169- onChanged: (value) {
170- if (field['required' ] && (value == null || value.isEmpty)) {
171- fieldErrors[field['name' ]] = true ;
172- } else {
173- fieldErrors[field['name' ]] = false ;
174- }
175- textValues[field['name' ]] = value; // Update textValues
176- setState (() {});
177- },
178- ),
179- ],
180- );
181- } else if (field['type' ] == 'radio' ) {
182- return Column (
183- crossAxisAlignment: CrossAxisAlignment .start,
184- children: [
185- Text (
186- field['name' ],
187- style: TextStyle (fontSize: 18 , fontWeight: FontWeight .bold),
188- ),
189- ...field['choices' ].map <Widget >((choice) {
190- return ListTile (
191- title: Text (choice),
192- leading: Radio <String >(
193- value: choice,
194- groupValue: radioValues[field['name' ]],
195- onChanged: (String ? value) {
196- if (value != null ) {
197- setState (() {
198- radioValues[field['name' ]] = value;
199- fieldErrors[field['name' ]] = false ;
200- });
201- }
202- },
159+ ],
160+ );
161+ } else if (field['type' ] == 'text' ) {
162+ return Column (
163+ children: [
164+ TextFormField (
165+ initialValue:
166+ textValues[field['name' ]] ?? '' , // Use the stored value
167+ decoration: InputDecoration (
168+ labelText: field['name' ],
169+ errorText: showError ? 'This field is required' : null ,
203170 ),
204- );
205- }).toList (),
206- showError
207- ? Text ('This field is required' ,
208- style: TextStyle (color: Colors .red))
209- : SizedBox .shrink (),
210- ],
211- );
171+ onChanged: (value) {
172+ if (field['required' ] &&
173+ (value == null || value.isEmpty)) {
174+ fieldErrors[field['name' ]] = true ;
175+ } else {
176+ fieldErrors[field['name' ]] = false ;
177+ }
178+ textValues[field['name' ]] = value; // Update textValues
179+ setState (() {});
180+ },
181+ ),
182+ ],
183+ );
184+ } else if (field['type' ] == 'radio' ) {
185+ return Column (
186+ crossAxisAlignment: CrossAxisAlignment .start,
187+ children: [
188+ Text (
189+ field['name' ],
190+ style: TextStyle (fontSize: 18 , fontWeight: FontWeight .bold),
191+ ),
192+ ...field['choices' ].map <Widget >((choice) {
193+ return ListTile (
194+ title: Text (choice),
195+ leading: Radio <String >(
196+ value: choice,
197+ groupValue: radioValues[field['name' ]],
198+ onChanged: (String ? value) {
199+ if (value != null ) {
200+ setState (() {
201+ radioValues[field['name' ]] = value;
202+ fieldErrors[field['name' ]] = false ;
203+ });
204+ }
205+ },
206+ ),
207+ );
208+ }).toList (),
209+ showError
210+ ? Text ('This field is required' ,
211+ style: TextStyle (color: Colors .red))
212+ : SizedBox .shrink (),
213+ ],
214+ );
215+ } else {
216+ return SizedBox
217+ .shrink (); // Return an empty widget for unsupported field types
218+ }
212219 } else {
213- return SizedBox
214- . shrink (); // Return an empty widget for unsupported field types
220+ return Text (
221+ "Please send pictures of the robot to the scouting channel" );
215222 }
216223 },
217224 ),
0 commit comments