[英]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.