下拉按钮颤动

发布于 2025-01-13 16:47:55 字数 1962 浏览 2 评论 0原文

我创建了一个下拉按钮,在我选择某些内容后,该区域是灰色的。有可能把它拿走吗? 我不知道是否有房产可以做到这一点,但目前还找不到。

输入图片此处描述

代码如下所示:

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(),
                    )),
                  ),,

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.

enter image description here

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(),
                    )),
                  ),,

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

阳光①夏 2025-01-20 16:47:55

灰色区域表示您的 DropdownButton 当前处于焦点状态。在 DropdownButton 中选择一个后,焦点仍保留在该值上。这就是它呈灰色的原因。如果您将焦点放在其他物体上,例如按钮或屏幕上,它们的灰色将会消失,因为它不再处于焦点上。
如果想改变灰色区域的颜色,可以设置 focusColor< /a>.

DropdownButton<DropdownOption>(
  focusColor: Colors.transparent,
  ...
),

The grey area indicates that your DropdownButton is currently focused. After selecting a value in your DropdownButton, the focus remains on it. This is the reason why it is grey. If you focus something else e.g. 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.

DropdownButton<DropdownOption>(
  focusColor: Colors.transparent,
  ...
),
方圜几里 2025-01-20 16:47:55
///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(),
                                        ),
                                      ),
                                    ),
                                  );
                                },
                              ),
///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(),
                                        ),
                                      ),
                                    ),
                                  );
                                },
                              ),
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文