簡體   English   中英

自定義 DropdownButton 的彈出菜單

[英]Customizing the popup menu of a DropdownButton

如何設置DropdownButton菜單的背景顏色。 我可以自定義出現的Text()項目,但它們出現在我想更改顏色的容器中。

看起來dropdownColor設置處理這個:

DropdownButton<String>(
  dropdownColor: Colors.blue,

 // ...
}

在此處輸入圖片說明

.. 通過自動完成提供的選項找到它

像這樣的事情會起作用:

          DropdownMenuItem<int>(
            value: model.id,
            child: SizedBox(
              width: width,
              child: Container(
                color: Colors.green, // 
                child: Text(
                  model.toString(),
                ),
              ),
            ),
          )
        ) 
int _value = 0;

Widget _buildDropdown() {
  return DropdownButton(
    value: _value,
    items: [
      DropdownMenuItem(
        value: 0,
        child: Container(
          color: Colors.blue, // you need this
          child: Text("Zero"),
          width: 100,
          alignment: Alignment.center,
        ),
      ),
      DropdownMenuItem(
        value: 1,
        child: Container(
          color: Colors.green, // you need this
          child: Text("One"),
          width: 100,
          alignment: Alignment.center,
        ),
      ),
    ],
    onChanged: (value) => setState(() => _value = value),
  );
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM