[英]Dropdownbutton Flutter
我创建了一个下拉按钮,在我选择了一些区域是灰色的之后。 有可能把它拿走吗? 我不知道是否有房产可以做到这一点,但还找不到。
代码如下所示:
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(),
)),
),,
灰色区域表示您的DropdownButton
当前处于焦点状态。 在您的DropdownButton
中选择一个value
后,焦点将保留在该值上。 这就是为什么它是灰色的原因。 如果您将焦点放在其他东西上,例如按钮或屏幕上,它们的灰色将消失,因为它不再处于焦点上。
如果你想改变灰色区域的颜色,你可以设置focusColor 。
DropdownButton<DropdownOption>(
focusColor: Colors.transparent,
...
),
///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(),
),
),
),
);
},
),
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.