Friday, October 9, 2026
HomeiOS Developmentandroid - Flutter - Validate Dropdown worth

android – Flutter – Validate Dropdown worth

[ad_1]

I am attempting to validate consumer enter within the dropdown button, nevertheless it would not work because it ought to plus the autovalidate is deprecated makes me much more confused. And I must validate one other textfield if consumer chosen one of many dropdown record.

Right here is the code for my dropdown button and the textfield(ignore the commented codes):

  //textfield controller
  TextEditingController sickController = TextEditingController();

  //Dropdown record values
  remaining objects = ['Healthy', 'Unhealthy'];

...

                  //Dropdown Listing | Well being
                  Container(
                    width: scrwidth * 0.8,
                    top: scrheight / 16,
                    ornament: const BoxDecoration(
                        colour: Colours.white,
                        borderRadius: BorderRadius.all(
                          Radius.round(8),
                        ),
                        boxShadow: [
                          BoxShadow(
                            color: Colors.black54,
                            blurRadius: 10,
                            offset: Offset(2, 2),
                          )
                         ]
                        ),
                    youngster: Row(
                      youngsters: [
                        SizedBox(
                          width: scrwidth / 18,
                        ),
                        Expanded(
                          child: Padding(
                            padding: const EdgeInsets.all(8.0),
                            child: DropdownButtonHideUnderline(
                              child: DropdownButtonFormField<String>(
                                // key: _sickkey,
                                // autovalidateMode: _autovalidate,
                                decoration: const InputDecoration(
                                  border: InputBorder.none,
                                  isDense: true,
                                ),
                                icon: const Icon(
                                  Icons.arrow_drop_down,
                                  color: Colors.black54,
                                ),
                                hint: const Text(
                                  "Health",
                                  style: TextStyle(
                                      fontFamily: "Ubuntu",
                                      fontWeight: FontWeight.w500),
                                ),
                                isExpanded: true,
                                value: value,
                                // validator: (value) =>
                                //     value == null ? 'field required' : null,
                                items: items.map(buildMenuItem).toList(),
                                onChanged: (value) =>
                                    setState(() {
                                  this.value = value;
                                  if (this.value == "Unhealthy") {
                                    isVisible = true;
                                  } else {
                                    isVisible = false;
                                  }
                                }),
                              ),
                            ),
                          ),
                        ),
                      ],
                    ),
                  ),
                  //Illness Textfield
                  Visibility(
                    youngster: Container(
                      width: scrwidth * 0.8,
                      top: scrheight / 16,
                      margin: const EdgeInsets.solely(high: 8),
                      ornament: const BoxDecoration(
                        colour: Colours.white,
                        borderRadius: BorderRadius.all(Radius.round(12)),
                        boxShadow: [
                          BoxShadow(
                            color: Colors.black26,
                            blurRadius: 10,
                            offset: Offset(2, 2),
                          )
                        ],
                      ),
                      youngster: Row(
                        youngsters: [
                          SizedBox(
                            width: scrwidth / 6,
                            child: Icon(
                              Icons.medication,
                              color: primary,
                              size: scrwidth / 15,
                            ),
                          ),
                          Expanded(
                            child: Padding(
                              padding: EdgeInsets.only(
                                right: scrwidth / 12,
                              ),
                              child: TextFormField(
                                controller: sickController,
                                enableSuggestions: false,
                                autocorrect: false,
                                decoration: InputDecoration(
                                  contentPadding: EdgeInsets.symmetric(
                                    vertical: scrheight / 50,
                                  ),
                                  border: InputBorder.none,
                                  hintText: "State your sickness",
                                ),
                              ),
                            ),
                          )
                        ],
                      ),
                    ),
                    seen: isVisible,
                  ),

Right here is the slide button that can ship all the information to the web to be saved in database utilizing php API:

                         onSubmit: () async {
                            print(identify +
                                " (" +
                                consumer.lg_username! +
                                ")" +
                                " checked in on " +
                                DateFormat('y-M-d HH:mm:ss a')
                                    .format(DateTime.now()) +
                                " at " +
                                location);
                            print(
                                //Well being? If Unhealthy, State illness
                                 );
                            Timer(const Length(seconds: 3), () {
                              key.currentState!.reset();
                            });
                          },
                        );

enter image description here

How do I save the enter from the dropdown proper earlier than consumer can work together the slide button talked about above, with out sending a null worth from each dropdown and textfield?

[ad_2]

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments