【发布时间】:2020-05-04 05:45:41
【问题描述】:
我制作了一个小部件列表,我想访问 DayButton 类中的 setter,但是当我尝试 days[index]. 时,它不显示 setter 方法,它会将输出视为一般小部件而不是 @ 987654323@小部件
这里是代码。
class DayButtonRow extends StatefulWidget{
@override
DBRState createState() => DBRState();
}
class DBRState extends State<DayButtonRow>{
currentDay(int i){
setState(() {
current = days.elementAt(i).key;
//I want to access the setter here to change the color of the button
});
}
@override
Widget build(BuildContext context) {
currentDay(3);
return Padding(
padding: const EdgeInsets.only(top: 8.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: days
),
);
}
}
Key current;
List<Widget> days = [
DayButton("MON"),
DayButton("TUE"),
DayButton("WED"),
DayButton("THU"),
DayButton("FRI"),
DayButton("SAT"),
DayButton("SUN"),
];
有没有办法从列表中访问DayButton 小部件类?
【问题讨论】:
-
声明天数为
List<DayButton>而不是List<Widget>? -
非常感谢你太傻了..