Drop down menu 颤振下拉按钮与父窗口小部件颜色相同
我一直在开发一个玩具提醒应用程序,希望为用户实现一个下拉菜单来选择给定的时间间隔 我有按钮加载,可以点击它与正确的菜单弹出。问题在于按钮在屏幕上的外观。它与父窗口小部件的颜色相同,并且根本不显示所选项目的文本 如何使下拉按钮具有白色背景和黑色文本 以下是一个屏幕截图: 下面是构建此视图的代码:Drop down menu 颤振下拉按钮与父窗口小部件颜色相同,drop-down-menu,colors,flutter,Drop Down Menu,Colors,Flutter,我一直在开发一个玩具提醒应用程序,希望为用户实现一个下拉菜单来选择给定的时间间隔 我有按钮加载,可以点击它与正确的菜单弹出。问题在于按钮在屏幕上的外观。它与父窗口小部件的颜色相同,并且根本不显示所选项目的文本 如何使下拉按钮具有白色背景和黑色文本 以下是一个屏幕截图: 下面是构建此视图的代码: @override Widget build(BuildContext context) { return new Container( child: new Row( childre
@override
Widget build(BuildContext context) {
return new Container(
child: new Row(
children: <Widget>[
new Expanded(
child: new Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
_buildInformationRow(),
_buildReminderRow(),
],
)
)
],
)
);
}
Widget _buildInformationRow() {
return new Container(
padding: const EdgeInsets.all(10.0),
child: new Row(
children: <Widget>[
new Column(
children: <Widget>[
new Container(
padding: const EdgeInsets.all(10.0),
child: new Text(
"This app can remind you to do stuff\non a regular basis",
style: new TextStyle(
color: Colors.white,
fontSize: 18.0,
)
),
)
],
)
],
),
);
}
Widget _buildReminderRow() {
return new Container(
child: new Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
new Column(
children: <Widget>[
new Container(
child: new Text(
"Remind me",
style: new TextStyle(
color: Colors.white,
fontSize: 18.0,
)
),
)
],
),
new Column(
children: <Widget>[
new Container(
child: new DropdownButton<String>(
style: new TextStyle(
color: Colors.black,
fontSize: 18.0,
),
items: <String>["Never", "Daily", "Hourly", "Every 30 Minutes"].map((String value) {
return new DropdownMenuItem <String>(
value: value,
child: new Text(value)
);
}).toList(),
onChanged: null
)
)
],
)
],
),
);
}
@覆盖
小部件构建(构建上下文){
退回新货柜(
孩子:新的一排(
儿童:[
新扩展(
子:新列(
crossAxisAlignment:crossAxisAlignment.stretch,
儿童:[
_buildInformationRow(),
_BuildRememberRow(),
],
)
)
],
)
);
}
小部件_buildInformationRow(){
退回新货柜(
填充:常数边集全部(10.0),
孩子:新的一排(
儿童:[
新专栏(
儿童:[
新容器(
填充:常数边集全部(10.0),
儿童:新文本(
“此应用程序可以提醒您定期做事情”,
样式:新文本样式(
颜色:颜色,白色,
字体大小:18.0,
)
),
)
],
)
],
),
);
}
小部件{
退回新货柜(
孩子:新的一排(
mainAxisAlignment:mainAxisAlignment.space,
儿童:[
新专栏(
儿童:[
新容器(
儿童:新文本(
“提醒我”,
样式:新文本样式(
颜色:颜色,白色,
字体大小:18.0,
)
),
)
],
),
新专栏(
儿童:[
新容器(
孩子:新的下拉按钮(
样式:新文本样式(
颜色:颜色,黑色,
字体大小:18.0,
),
项目:[“从不”、“每天”、“每小时”、“每30分钟”].map((字符串值){
返回新的DropdownMenuItem(
价值:价值,
子项:新文本(值)
);
}).toList(),
onChanged:null
)
)
],
)
],
),
);
}
您是否尝试过将下拉列表包装在白色容器中,然后确保DropdownButton style属性中的子项具有黑色的TextStyle
new Container(
color: Colors.white,
child: DropdownButtonHideUnderline(
child: ButtonTheme(
alignedDropdown: true,
child: DropdownButton<T>(
items: dropdownItems,
onChanged: this.onChanged,
value: this.preSelected,
style: new TextStyle(
color: Colors.black,
),
),
)
),
),
主题(
数据:新主题数据(
画布颜色:颜色。红色,
原色:颜色。黑色,
颜色:颜色。黑色,
颜色:颜色。黑色),
孩子:下拉按钮(
iconEnabledColor:Colors.white,
样式:TextStyle(颜色:_selectedColor,fontSize:16),
下划线:文本(“”),
值:选择的货币,
是的,
iconSize:40,
项目:货币。条目
.地图(
(地图条目e)=>
下拉菜单项(
值:e.key,
子项:文本(即值),
))
.toList(),
onChanged:(字符串newKey){
设置状态(){
_selectedColor=Colors.white;
selectedCurrency=newKey;
});
},
))
使用提示而不是值
范例
提示:dropdownValue==null?文本(“选择一个”,样式:TextStyle(颜色:Colors.red)):文本(下拉值,样式:TextStyle(颜色:Colors.green))
dropdownValue是我选择的值您可以使用以下代码为DropDownButton提示提供自定义颜色
DropdownButton<String>(
isExpanded: true,
hint: Text('Your hint',style: TextStyle(color: Color(0xFFF5F5F5)),),
icon: Icon(Icons.arrow_downward),
iconSize: 20,
elevation: 12,
style: TextStyle(color: Colors.lightBlue),
underline: Container(
height: 0,
),
items: _currencies
.map<DropdownMenuItem<String>>((String value) {
return DropdownMenuItem<String>(
value: value,
child: Text(
value,
style: TextStyle(fontSize: 14.0, color: Color(0xFFF5F5F5)),
),
);
}).toList(),
onChanged: (String valueSelected) {
onDropDownItemChanged(valueSelected);
},
value: dropdownValue,
//00000value: dropdownValue,
),
下拉按钮(
是的,
提示:文本('您的提示',样式:文本样式(颜色:颜色(0xFFF5)),),
图标:图标(图标。向下箭头),
iconSize:20,
标高:12,
样式:TextStyle(颜色:Colors.lightBlue),
下划线:容器(
高度:0,,
),
项目:\货币
.map((字符串值){
返回下拉菜单项(
价值:价值,
子:文本(
价值
样式:TextStyle(fontSize:14.0,颜色:color(0xFFF5)),
),
);
}).toList(),
onChanged:(字符串值已选定){
onDropDownItemChanged(选择值);
},
value:dropdownValue,
//00000值:dropdownValue,
),
您可以通过
DropdownButtonHideUnderline(
child: Theme(
data: ThemeData(
primaryColor: Colors.white,
),
child: DropdownButton<String>(
isExpanded: true,
value: _selectedMetalColor,
onChanged: (String newValue) {
setState(() {
_selectedMetalColor = newValue;
//dropdownValue = newValue;
});
},
// hint: Text(
// teethMetalColors[0],
// style: TextStyle(
// color: Colors.white,
// ),
// ),
icon: Container(
margin: EdgeInsets.only(right: 12.0),
child: Icon(
// Add this
Icons.keyboard_arrow_down, // Add this
color: Colors.white, // Add this
size: 35.0,
),
),
style: TextStyle(
color: Colors.black, fontSize: 16.0),
selectedItemBuilder:
(BuildContext context) {
return teethMetalColors
.map((String value) {
return Padding(
padding: const EdgeInsets.only(
top: 12.0, left: 16.0),
child: Text(
_selectedMetalColor,
style:
TextStyle(color: Colors.white),
),
);
}).toList();
},
items: teethMetalColors
.map<DropdownMenuItem<String>>(
(String value) {
return DropdownMenuItem<String>(
value: value,
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Text(
value,
style:
TextStyle(color: Colors.black),
),
),
);
}).toList(),
),
),
)
DropdownButtonHideUnderline(
儿童:主题(
数据:主题数据(
原色:颜色。白色,
),
孩子:下拉按钮(
是的,
值:\您选择的金属颜色,
onChanged:(字符串newValue){
设置状态(){
_selectedMetalColor=新值;
//dropdownValue=newValue;
});
},
//提示:文本(
//齿金属颜色[0],
//样式:TextStyle(
//颜色:颜色,白色,
// ),
// ),
图标:容器(
边距:仅限边集(右:12.0),
子:图标(
//加上这个
Icons.keyboard\u arrow\u down,//添加这个
颜色:Colors.white,//添加此
尺寸:35.0,
DropdownButton<String>(
isExpanded: true,
hint: Text('Your hint',style: TextStyle(color: Color(0xFFF5F5F5)),),
icon: Icon(Icons.arrow_downward),
iconSize: 20,
elevation: 12,
style: TextStyle(color: Colors.lightBlue),
underline: Container(
height: 0,
),
items: _currencies
.map<DropdownMenuItem<String>>((String value) {
return DropdownMenuItem<String>(
value: value,
child: Text(
value,
style: TextStyle(fontSize: 14.0, color: Color(0xFFF5F5F5)),
),
);
}).toList(),
onChanged: (String valueSelected) {
onDropDownItemChanged(valueSelected);
},
value: dropdownValue,
//00000value: dropdownValue,
),
DropdownButtonHideUnderline(
child: Theme(
data: ThemeData(
primaryColor: Colors.white,
),
child: DropdownButton<String>(
isExpanded: true,
value: _selectedMetalColor,
onChanged: (String newValue) {
setState(() {
_selectedMetalColor = newValue;
//dropdownValue = newValue;
});
},
// hint: Text(
// teethMetalColors[0],
// style: TextStyle(
// color: Colors.white,
// ),
// ),
icon: Container(
margin: EdgeInsets.only(right: 12.0),
child: Icon(
// Add this
Icons.keyboard_arrow_down, // Add this
color: Colors.white, // Add this
size: 35.0,
),
),
style: TextStyle(
color: Colors.black, fontSize: 16.0),
selectedItemBuilder:
(BuildContext context) {
return teethMetalColors
.map((String value) {
return Padding(
padding: const EdgeInsets.only(
top: 12.0, left: 16.0),
child: Text(
_selectedMetalColor,
style:
TextStyle(color: Colors.white),
),
);
}).toList();
},
items: teethMetalColors
.map<DropdownMenuItem<String>>(
(String value) {
return DropdownMenuItem<String>(
value: value,
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Text(
value,
style:
TextStyle(color: Colors.black),
),
),
);
}).toList(),
),
),
)
Container(
padding: const EdgeInsets.only(left: 0.0, right: 10.0),
decoration: BoxDecoration(
color: Colors.cyanAccent,
),
child: DropdownButtonHideUnderline(
child: new DropdownButton<String>(
style: new TextStyle(
color: Colors.black,
fontSize: 18.0,
),
items: <String>["Never", "Daily", "Hourly", "Every 30 Minutes"].map((String value) {
return new DropdownMenuItem <String>(
value: value,
child: new Text(value)
);
}).toList(),
onChanged: null
),
),
)