简体   繁体   English

如何为 flutter 中的下拉添加所需的验证?

[英]How to add required validation for drop down in flutter?

Please refer below code.请参考下面的代码。 I have to add required validation here.我必须在这里添加必需的验证。
Container( height: MediaQuery.of(context).size.height * 0.07, width: MediaQuery.of(context).size.width * 0.4, child: InputDecorator( decoration: InputDecoration( errorStyle: const TextStyle(fontSize: 0.05),容器(高度:MediaQuery.of(上下文).size.height * 0.07,宽度:MediaQuery.of(上下文).size.width * 0.4,子:InputDecorator(装饰:InputDecoration(errorStyle:const TextStyle(fontSize:0.05),

                    //  fillColor: Colors.grey[10],
                    border: OutlineInputBorder(
                        borderSide: BorderSide(
                      color: Colors.black,
                      // width: 10
                    )),
                  ),
                  // child: Padding(
                  //   padding: EdgeInsets.only(top: 4),
                  child: DropdownButtonHideUnderline(
                    child: DropdownButton2(
                      hint: Text(
                        'Select Document Status',
                        style: TextStyle(
                          fontSize: 8,
                          //color: Theme.of(context).hintColor,
                        ),
                      ),
                      items: items1
                          .map((item) => DropdownMenuItem<String>(
                                value: item,
                                child: Text(
                                  item,
                                  style: const TextStyle(
                                    fontSize: 10,
                                  ),
                                ),
                              ))
                          .toList(),
                      value: selectedItem,
                      onChanged: (value) {
                        setState(() {
                          selectedItem = value as String;
                        });
                      },
                      //isExpanded: true,
                      buttonHeight: 20,
                      buttonWidth: 150,
                      itemHeight: 40,
                      dropdownWidth: 200,
                    ),
                  ),
                ),
              ),

you need to use "DropdownButtonFormField2" which have a validator.您需要使用具有验证器的“DropdownButtonFormField2”。

DropdownButtonFormField2(
  validator: (value){
   ///---check
  },
)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM