我想让我的孩子在最初阶段变得隐形。然后孩子需要显示图标onTap。在我的代码中,_yes是我需要进行更改的子级。
InkWell(
onTap: () {
setState(() {
_ansContainer = _ansContainer == Colors.grey ? Colors.green : Colors.grey;
_done = _done == Colors.transparent ? Colors.green : Colors.transparent;
});
},
child: Container(
margin: EdgeInsets.only(top: 10),
padding: EdgeInsets.all(8.0),
decoration: BoxDecoration(
border: Border.all(color: _ansContainer),
borderRadius: BorderRadius.circular(15),
), //decoration
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
'Answer 1', style: TextStyle(color: Colors.grey, fontSize: 16), //textStyle
), //text
Container(
height: 26,
width: 26,
decoration: BoxDecoration(
color: _done,
borderRadius: BorderRadius.circular(50.0),
border: Border.all(color: _ansContainer),
), //boxdecoration
child: Icon(_yes),
), //container
], //widget
), //row
),
), //container发布于 2021-10-25 08:00:08
您可以在onTap函数上创建布尔变量和设置状态。并将行小部件签入到天气以显示或不显示它。
final bool visible = false;
InkWell(
onTap: () {
setState(() {
visible != visible;
_ansContainer = _ansContainer == Colors.grey ? Colors.green : Colors.grey;
_done = _done == Colors.transparent ? Colors.green : Colors.transparent;
});
},
child: Container(
margin: EdgeInsets.only(top: 10),
padding: EdgeInsets.all(8.0),
decoration: BoxDecoration(
border: Border.all(color: _ansContainer),
borderRadius: BorderRadius.circular(15),
), //decoration
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
'Answer 1', style: TextStyle(color: Colors.grey, fontSize: 16), //textStyle
), //text
//check statement here
(visible == true)?Container(
height: 26,
width: 26,
decoration: BoxDecoration(
color: _done,
borderRadius: BorderRadius.circular(50.0),
border: Border.all(color: _ansContainer),
), //boxdecoration
child: Icon(_yes),
):SizedBox(), //container
], //widget
), //row
),
), //containerhttps://stackoverflow.com/questions/69704246
复制相似问题