[英]How to create rectangle icon button without label in flutter?
we can create the icon button with FlatButton.icon()
but it requires label
parameter.我们可以使用
FlatButton.icon()
创建图标按钮,但它需要label
参数。 we can also use IconButton()
but it makes a circular icon button.我们也可以使用
IconButton()
但它会生成一个圆形图标按钮。
how to make a rectangle icon button like FlatButton()
but with just icon in flutter?如何制作一个像
FlatButton()
这样的矩形图标按钮,但在 flutter 中只有图标?
Container(
height: 100.0,
width: 100.0,
child: FlatButton(
child: Icon(Icons.place),
onPressed: () {},
),
),
You can create a container with an icon as a child and wrap the container with the InkWell widget to make it clickable.您可以创建一个带有图标的容器作为子项,并使用 InkWell 小部件包装容器以使其可点击。 This way you can shape your container to your need, which in this case is a rectangle.
通过这种方式,您可以根据需要塑造您的容器,在这种情况下是一个矩形。
Here's a code sample -这是一个代码示例 -
InkWell(
child: Container(
decoration: BoxDecoration(
shape: BoxShape.rectangle,
border: Border.all(
width: 1,
)),
child: Icon(Icons.add, color: Colors.black),
),
onTap: () {},
),
Using Inkwell combination with container you can make customized button easily as done in above example将 Inkwell 与容器结合使用,您可以轻松制作自定义按钮,如上例所示
InkWell(
child: Container(
decoration: BoxDecoration(
shape: BoxShape.rectangle,
border: Border.all(
width: 1,
)),
child: Icon(Icons.add, color: Colors.black),
),
onTap: () {},
),
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.