我试图制作一个包含int和string值的下拉按钮,但我不知道如何同时调用string和int。
编码
int selectedValue = 10;
List<DropdownMenuItem<int>> dropdownItems = [
DropdownMenuItem(
value: 10,
child: Text(
'Small',
style: TextStyle(
fontSize: 20,
fontFamily: 'Inconsolata',
fontWeight: FontWeight.bold,
color: Color(0xCBFDC4AB),
),
),
),
const DropdownMenuItem(
value: 20,
child: Text(
'Medium',
style: TextStyle(
fontSize: 20,
fontFamily: 'Inconsolata',
fontWeight: FontWeight.bold,
color: Color(0xCBFDC4AB),
),
),
),
const DropdownMenuItem(
value: 30,
child: Text(
'Large',
style: TextStyle(
fontSize: 20,
fontFamily: 'Inconsolata',
fontWeight: FontWeight.bold,
color: Color(0xCBFDC4AB),
),
),
),
];'
//int值的文本
Text(
"\$$selectedValue",
style: const TextStyle(
fontSize: 40,
fontFamily: 'Inconsolata',
fontWeight: FontWeight.bold,
color: Color(0xADFFF0E8),
),
),
//字符串值的文本
Text (value),
// dropdownbutton
DropdownButton(
value: selectedValue,
items: dropdownItems,
dropdownColor: Colors.brown,
underline: Container(
height: 3,
color: const Color(0xCBFDC4AB),
),
icon: Icon(
CupertinoIcons.arrowtriangle_down_fill,
color: const Color(0xCBFDC4AB),
size: 10,
shadows: [
Shadow(
color: Colors.yellow.withOpacity(0.9),
blurRadius: 10,
)
],
),
onChanged: (int? newValue) {
setState(() {
selectedValue = newValue!;
});
},
),
我希望子文本是字符串值,而dropdownitem的值是tre int value。
谢谢你。
1条答案
按热度按时间zz2j4svz1#
DropdownMenuItem
的列表,值为int