我想在内部容器中显示图标



我想让我的孩子在初始阶段不可见。然后孩子需要显示图标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

可以创建bool变量和setstate on 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
),
), //container

相关内容

  • 没有找到相关文章

最新更新