Flutter - Container onPressed?

后端 未结 6 1649
孤街浪徒
孤街浪徒 2021-01-30 20:01

I have this container:

  new Container(
    width: 500.0,
    padding: new EdgeInsets.fromLTRB(20.0, 40.0, 20.0, 40.0),
    color: Colors.green,
    child: new C         


        
6条回答
  •  时光说笑
    2021-01-30 20:08

    Just wanted to add on to The Dumbfounds answer(accepted ans above)

    If you are using GestureDetector or InkWell to handle the click of a group of icon and text, then use Icon widget instead of IconButton to display the icon as the onPressed method of IconButton will take over the onTap method of GestureDetector/InkWell and as a result the onTap then will only work if you click on the text.

    Example -

    @override
      Widget build(BuildContext context) {
        return Row(mainAxisSize: MainAxisSize.min, children: [
          GestureDetector(
            onTap: () {
              _toggleFavorite();
            },
            child: Row(
              children: [
                Container(
                  padding: EdgeInsets.all(0.0),
                  child: _isFavorited ? Icon(Icons.star, color: Colors.red[500]) : Icon(Icons.star_border),
                ),
                SizedBox(
                  width: 18.0,
                  child: Container(
                    child: Text('$_favoriteCount'),
                  ),
                )
              ],
            ),
          )
        ]);
      }
    }
    

提交回复
热议问题