DropdownButtonFormField和`alignedDropdown`属性

时间:2019-04-01 11:32:30

标签: flutter

我在表单中使用了DropdownButtonFormField。另外,我希望其在展开视图中的宽度与下拉按钮的宽度相同,因此我将其包装在ButtonTheme中并设置了alignedDropdown: true

但是这导致了一个副作用,现在我不知道该如何纠正:它为提示文本添加了一个额外的左填充,如下面的屏幕快照所示。您能建议如何解决此问题吗? 如果删除ButtonTheme,则提示填充与其他表单字段中的标签相同,但下拉菜单的宽度不适合我。 enter image description here

来源:

Row(
  children: <Widget>[
    Flexible(
      flex: 4,
      child: ButtonTheme(
        alignedDropdown: true,
        child: DropdownButtonFormField(
          items: phoneTypeMenuItems(),
          hint: Text('Phone type'),
        ),
      ),
    ),
    SizedBox(width:16),
    Flexible(
      child: TextFormField(
        decoration: InputDecoration(
          labelText: "Phone", 
          contentPadding: EdgeInsets.
          symmetric(vertical: 4)
        ),
        keyboardType: TextInputType.number,
        inputFormatters: [
          WhitelistingTextInputFormatter.digitsOnly, 
          LengthLimitingTextInputFormatter(10), 
          BlacklistingTextInputFormatter.singleLineFormatter],
      ),
      flex: 5,
    )
  ],
),

1 个答案:

答案 0 :(得分:0)

我认为ButtonTheme应该是DropdownButtonFormField的孩子,而不是相反。