Flutter 如何更改列表中单个按钮的颜色-颤振
当用户选择一个选项时,我在尝试更改按钮的颜色时遇到问题。如何在单击时选择所选索引并更改其颜色 提前谢谢 我在下面添加了我的代码和屏幕截图Flutter 如何更改列表中单个按钮的颜色-颤振,flutter,dart,flutter-layout,Flutter,Dart,Flutter Layout,当用户选择一个选项时,我在尝试更改按钮的颜色时遇到问题。如何在单击时选择所选索引并更改其颜色 提前谢谢 我在下面添加了我的代码和屏幕截图 List<dynamic> getChoices() { var choices = []; // for (int i = 0; i < choicesText.length; i++) { var eachChoice = choicesText[i]['name']; var newChoi
List<dynamic> getChoices() {
var choices = []; //
for (int i = 0; i < choicesText.length; i++) {
var eachChoice = choicesText[i]['name'];
var newChoice = Expanded(
child: Padding(
padding: EdgeInsets.all(15.0),
child: FlatButton(
color: Colors.red,
child: Text(
eachChoice,
style: TextStyle(
fontSize: 20.0,
color: Colors.white,
),
),
onPressed: () {
//The user picked this button.
userChoice = eachChoice;
},
),
),
);
choices.add(newChoice);
}
return choices;
}
List getChoices(){
var选择=[]//
for(int i=0;i
您可以创建一个
var
并设置一个小部件,我希望它对您有用
List<dynamic> getChoices() {
var choices = []; //
for (int i = 0; i < choicesText.length; i++) {
var eachChoice = choicesText[i]['name'];
var colorChoice = if (eachChoice = 1) return Colors.red else return Colors.red
var newChoice = Expanded(
child: Padding(
padding: EdgeInsets.all(15.0),
child: FlatButton(
color: colorChoice,
child: Text(
eachChoice,
style: TextStyle(
fontSize: 20.0,
color: Colors.white,
),
),
onPressed: () {
//The user picked this button.
userChoice = eachChoice;
},
),
),
);
choices.add(newChoice);
}
return choices;
}
List getChoices(){
var选择=[]//
for(int i=0;i