颤振下拉列表 - 检索选定的值而不是框格式
flutter drop-down list - retrieve selected value and not in a box format
我做了一个下拉列表,如下图所示
enter image description here
这里:
- 我希望下拉菜单像其他 TextFormFields 一样位于一个框中,并且箭头更大
- 我的下拉列表背景似乎模糊不清
- 我希望在“选择身份证明”中替换所选值
以下是我的代码:
Container(
padding: EdgeInsets.symmetric(horizontal: 20),
color: Colors.white,
child: _hintDown(),
),
SizedBox(height: 10),
我的下拉代码是:
DropdownButton _hintDown() => DropdownButton<String>(
items: [
DropdownMenuItem<String>(
value: "1",
child: Text(
"Aadhar Card",
),
),
DropdownMenuItem<String>(
value: "2",
child: Text(
"Pancard",
),
),
],
onChanged: (value) {
print("value: $value");
},
hint: Text(
"Choose the id proof!",
style: TextStyle(
color: Colors.black,
),
),
);
这个代码够用了还是我需要换其他的?
根据要求对代码进行了一定的改动。您必须访问 flutter 文档并阅读有关使用 DropdownButton class 实现您想要的内容的信息
清楚地查看代码,并在您的代码库中实现代码
// look at the comments too to understand the functionality
String dropdownValue = 'Choose the id proof!';
// Return a widgt container to give the border
// and then wrap it around your DropdownButton
Widget _hintDown() => Container(
decoration: BoxDecoration(
border: Border.all(color: Colors.grey),
borderRadius: BorderRadius.circular(8.0)
),
child: Padding(
padding: EdgeInsets.all(5.0),
child: DropdownButton<String>(
value: dropdownValue,
icon: Icon(Icons.arrow_drop_down),
iconSize: 30, //this inicrease the size
elevation: 16,
style: TextStyle(color: Colors.black),
// this is for underline
// to give an underline us this in your underline inspite of Container
// Container(
// height: 2,
// color: Colors.grey,
// )
underline: Container(),
onChanged: (String newValue) {
setState(() {
dropdownValue = newValue;
});
},
items: <String>['Choose the id proof!', 'Adhaar Card', 'Pancard', 'Voter card', 'Passport']
.map<DropdownMenuItem<String>>((String value) {
return DropdownMenuItem<String>(
value: value,
child: Text(value),
);
}).toList(),
)
)
);
结果
我做了一个下拉列表,如下图所示 enter image description here
这里:
- 我希望下拉菜单像其他 TextFormFields 一样位于一个框中,并且箭头更大
- 我的下拉列表背景似乎模糊不清
- 我希望在“选择身份证明”中替换所选值 以下是我的代码:
Container(
padding: EdgeInsets.symmetric(horizontal: 20),
color: Colors.white,
child: _hintDown(),
),
SizedBox(height: 10),
我的下拉代码是:
DropdownButton _hintDown() => DropdownButton<String>(
items: [
DropdownMenuItem<String>(
value: "1",
child: Text(
"Aadhar Card",
),
),
DropdownMenuItem<String>(
value: "2",
child: Text(
"Pancard",
),
),
],
onChanged: (value) {
print("value: $value");
},
hint: Text(
"Choose the id proof!",
style: TextStyle(
color: Colors.black,
),
),
);
这个代码够用了还是我需要换其他的?
根据要求对代码进行了一定的改动。您必须访问 flutter 文档并阅读有关使用 DropdownButton class 实现您想要的内容的信息
清楚地查看代码,并在您的代码库中实现代码
// look at the comments too to understand the functionality
String dropdownValue = 'Choose the id proof!';
// Return a widgt container to give the border
// and then wrap it around your DropdownButton
Widget _hintDown() => Container(
decoration: BoxDecoration(
border: Border.all(color: Colors.grey),
borderRadius: BorderRadius.circular(8.0)
),
child: Padding(
padding: EdgeInsets.all(5.0),
child: DropdownButton<String>(
value: dropdownValue,
icon: Icon(Icons.arrow_drop_down),
iconSize: 30, //this inicrease the size
elevation: 16,
style: TextStyle(color: Colors.black),
// this is for underline
// to give an underline us this in your underline inspite of Container
// Container(
// height: 2,
// color: Colors.grey,
// )
underline: Container(),
onChanged: (String newValue) {
setState(() {
dropdownValue = newValue;
});
},
items: <String>['Choose the id proof!', 'Adhaar Card', 'Pancard', 'Voter card', 'Passport']
.map<DropdownMenuItem<String>>((String value) {
return DropdownMenuItem<String>(
value: value,
child: Text(value),
);
}).toList(),
)
)
);
结果