繁体   English   中英

即使我在提示文本上使用 AutoSizeText 小部件,为什么我的下拉菜单会溢出?

[英]Why is my Dropdown overflowing even though I use the AutoSizeText widget on the hint text?

我试图让我的 DropDowns 更具响应性,但我在这样做时遇到了问题。 我在文本上使用 AutoSizeText 小部件,但它仍然溢出。 最后有一个小下拉箭头可能会导致它,但我不确定为什么会这样或如何解决这个问题。 如果有人有这方面的经验或可以提供任何建议,我将不胜感激! 谢谢!

目前的样子。 它的溢出这是不好的。 我似乎无法让它不溢出。 我不认为是文字造成的

在此处输入图片说明

这是它的代码

 stateDropDown() {
    return Container(
        child: Center(
            child: Container(
              padding: EdgeInsets.symmetric(horizontal: 30),
              child: FormField<String>(
                builder: (FormFieldState<String> state) {
                  return Container(
                    decoration: BoxDecoration(
                        border: Border.all(color: Colors.white),
                        borderRadius: BorderRadius.circular(10.0),
                        color: Colors.white
                    ),
                    child: InputDecorator(
                      decoration: InputDecoration(
                          border: OutlineInputBorder(
                              borderRadius: BorderRadius.circular(10.0))),
                      child: DropdownButtonHideUnderline(
                        child: DropdownButton<String>(
                          hint: AutoSizeText("Please Select a State or Province", style: TextStyle(color: Colors.blue, fontFamily: 'Montserrat')),
                          value: currentSelectedState,
                          isDense: true,
                          onChanged: (newValue) {
                            setState(() {
                              currentSelectedState = newValue;
                            });
                          },
                          items: stateList.map((String value) {
                            return DropdownMenuItem<String>(
                              value: value,
                              child: Text(value),
                            );
                          }).toList(),
                        ),
                      ),
                    ),
                  );
                },
              ),
            )));
  }

尝试用缩小方法将 AutoSizeText 小部件换成包含在 FittedBox 小部件中的普通 Text() 小部件。

FittedBox(
    fit: BoxFit.scaleDown,
    child: Text(
        'Select State or Province', 
        style: TextStyle(color: Colors.blue, fontFamily: 'Montserrat',
    ),
),

AutoSizeText小部件中尝试maxLines:1

 hint: AutoSizeText("Please Select a State or Province",maxLines:1 ,style: TextStyle(color: Colors.blue, fontFamily: 'Montserrat')),

终于在一个帖子中找到了解决方案。 只需将isExpanded: true,添加到 DropDownButton

暂无
暂无

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

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