【发布时间】:2020-12-01 20:02:38
【问题描述】:
我很陌生,所以如果这个问题感觉微不足道或不需要,我很抱歉!
我有一个 Toggle 小部件,它包含一个带有 5 个子级的 Row 小部件,但我还添加了 4 个 SizedBox 来创建 5 个 Container 小部件之间的差异。
我希望这 5 个容器在单击时显示不同的颜色,并存储一个与之关联的 int 值。
我关注了官方文档和 Youtube 视频,但没有走多远。 这是我的代码:
ToggleButtons(
isSelected: <bool>[true, false, false, false, false, false, false, false, false],
children: <Widget>[
GestureDetector(
child: Container(
height: 85,
width: 85,
decoration: BoxDecoration(
color: _colour,
borderRadius: BorderRadius.circular(10)
),
child: Padding(
padding: EdgeInsets.all(8),
child: Image(
image: AssetImage('images/happy_icon.png'),
width: 75,
),
)
),
onTap: () {
setState(() {
remind = 1;
});
},
),
SizedBox(
width: 8,
),
// ... 3 more widgets like these
GestureDetector(
child: Container(
height: 85,
width: 85,
decoration: BoxDecoration(
color: _colour,
borderRadius: BorderRadius.circular(10)
),
child: Padding(
padding: EdgeInsets.all(8),
child: Image(
image: AssetImage('images/sad.png'),
width: 75,
),
)
),
onTap: () {
setState(() {
remind = 5;
});
},
)
selectedColor: _selectedColour,
onPressed: (int index) {
setState(() {
for (int buttonIndex = 0; buttonIndex < isSelected.length; buttonIndex++) {
if (buttonIndex == index) {
isSelected[buttonIndex] = !isSelected[buttonIndex];
} else {
isSelected[buttonIndex] = false;
}
}
});
},
【问题讨论】:
标签: flutter widget flutter-layout hybrid-mobile-app