首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >我想把图标ontap放在容器内

我想把图标ontap放在容器内
EN

Stack Overflow用户
提问于 2021-10-25 07:31:11
回答 1查看 35关注 0票数 0

我想让我的孩子在最初阶段变得隐形。然后孩子需要显示图标onTap。在我的代码中,_yes是我需要进行更改的子级。

代码语言:javascript
复制
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
EN

回答 1

Stack Overflow用户

发布于 2021-10-25 08:00:08

您可以在onTap函数上创建布尔变量和设置状态。并将行小部件签入到天气以显示或不显示它。

代码语言:javascript
复制
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
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/69704246

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档