简体   繁体   English

下拉按钮 Flutter

[英]Dropdownbutton Flutter

I created a dropdownbutton, after i chose something the area is grey.我创建了一个下拉按钮,在我选择了一些区域是灰色的之后。 Is it possible to get it away?有可能把它拿走吗? I don´t know if theres an property to do it, but can´t find one yet.我不知道是否有房产可以做到这一点,但还找不到。

在此处输入图像描述

The code looks like this:代码如下所示:

Container(
                      child: const Text('Multiplechoice?',
                          style: TextStyle(fontSize: 16)),
                      alignment: Alignment.center,
                      padding: const EdgeInsets.fromLTRB(0, 0, 10.0, 0),
                      margin: const EdgeInsets.fromLTRB(0, 0, 0, 15.0)),
                  Container(
                    width: 300,
                    padding: const EdgeInsets.symmetric(
                        horizontal: 8, vertical: 2),
                    decoration: BoxDecoration(
                      borderRadius: BorderRadius.circular(12),
                      border: Border.all(color: Colors.black, width: 2),
                    ),
                    child: DropdownButtonHideUnderline(
                        child: DropdownButton<DropdownOption>(
                      value: service.getSeventhOption,
                      isExpanded: true,
                      hint: const Text('Please choose'),
                      style: Constants.questionStyle,
                      iconSize: 20,
                      icon: const Icon(Icons.arrow_drop_down,
                          color: Colors.black),
                      onChanged: (DropdownOption? newValue) {
                        service.setSeventhOption = newValue!;
                      },
                      items: service.seventhDropdown
                          .map((DropdownOption option) {
                        return DropdownMenuItem<DropdownOption>(
                          value: option,
                          child: Text(option.text!),
                        );
                      }).toList(),
                    )),
                  ),,

The grey area indicates that your DropdownButton is currently focused.灰色区域表示您的DropdownButton当前处于焦点状态。 After selecting a value in your DropdownButton , the focus remains on it.在您的DropdownButton中选择一个value后,焦点将保留在该值上。 This is the reason why it is grey.这就是为什么它是灰色的原因。 If you focus something else eg a button or on the screen, they grey color will disappear, since it isn't on focus anymore.如果您将焦点放在其他东西上,例如按钮或屏幕上,它们的灰色将消失,因为它不再处于焦点上。
If you want to change the color of the grey area, you can set the focusColor .如果你想改变灰色区域的颜色,你可以设置focusColor

DropdownButton<DropdownOption>(
  focusColor: Colors.transparent,
  ...
),
///you can try this way I created my dropdown like this. hope this will work for you

  var _currentSelectedValue;
  var _currencies = [
    "Train",
    "Flight",
    "Car",
    "Dinner",
    "BreakFast",
    "Lunch",
    "Accommodation",
    "Mileage Allowance",
  ];



 FormField<String>(
                                builder: (FormFieldState<String> state) {
                                  return Container(
                                    width: _width! * 0.90,
                                    child: InputDecorator(
                                      decoration: InputDecoration(
                                        contentPadding:
                                            EdgeInsets.fromLTRB(10, 10, 10, 15),
                                        /*contentPadding:
                                    EdgeInsets.symmetric(vertical: 10.0, horizontal: 10.0),*/
                                        isDense: true,
                                        errorStyle: TextStyle(
                                            color: Colors.redAccent,
                                            fontSize: 16.0),
                                        hintText: 'Please select expense',
                                        labelStyle: TextStyle(
                                            color: AppColors.hotelListDarkBlue),
                                        hintStyle: TextStyle(
                                            color: AppColors.hotelListDarkBlue),
                                        border: OutlineInputBorder(
                                          borderRadius: BorderRadius.circular(10.0),
                                          borderSide: BorderSide(
                                            color: AppColors.textFieldColor,
                                          ),
                                        ),
                                        focusedBorder: OutlineInputBorder(
                                          borderRadius: BorderRadius.circular(10.0),
                                          borderSide: BorderSide(
                                            color: AppColors.baseLightBlueColor,
                                          ),
                                        ),
                                      ),
                                      isEmpty: _currentSelectedValue == '',
                                      child: DropdownButtonHideUnderline(
                                        child: DropdownButton<String>(
                                          icon: Icon(
                                            Icons.arrow_drop_down_sharp,
                                            color: AppColors.baseLightBlueColor,
                                          ),
                                          hint: Text(
                                            'Please select expense',
                                            style: TextStyle(
                                                color: AppColors.hotelListDarkBlue),
                                          ),
                                          value: _currentSelectedValue,
                                          isDense: true,
                                          onChanged: (String? newValue) {
                                            setState(() {
                                              _currentSelectedValue = newValue;
                                              state.didChange(newValue);
                                            });
                                          },
                                          items: _currencies.map((String value) {
                                            return DropdownMenuItem<String>(
                                              value: value,
                                              child: Text(value),
                                            );
                                          }).toList(),
                                        ),
                                      ),
                                    ),
                                  );
                                },
                              ),

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

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