Flutter-自定义按钮点击区域 [英] Flutter - Custom button tap area
问题描述
我正在构建Flutter应用程序,其中屏幕的很大一部分将被圆形按钮占据.
I'm building a Flutter application where a big portion of the screen will be occupied by a circular button.
我已经尝试了几种不同的方法来创建圆形按钮,但是我总是遇到同样的问题:可敲击"区域实际上不是圆形的,而是矩形的.
I already tried several different approaches in order to create a circular button, but I always end up having the same problem: the 'tappable' area is not actually circular, but rectangular.
以下是通过 FloatingActionButton
获得的示例:
Here is an example obtained with a FloatingActionButton
:
对于小尺寸按钮来说,这实际上不是问题-我什至会说这很有帮助-但就我而言,这很烦人.
For small-sized buttons this is not really a problem - I would even say that it is somehow helpful - but in my case it is very annoying.
所以我的问题是:是否可以将可敲击"区域限制为一个圆形?
So my question is: is it possible to restrict the 'tappable' area to a circle?
谢谢.
推荐答案
这似乎行得通,我不知道这样做是否正确,或者是否有更好的方法,但是您可以尝试.
This seems to work, I don't know if it is right to do so or if there is a better way but here you go.
class Test extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(),
body: Container(
color: Colors.blue,
child: Center(
child: GestureDetector(
onTap: () {
print('clicky');
},
child: ClipOval(
child: Container(
width: 200,
height: 200,
color: Colors.red,
),
),
),
),
),
);
}
}
这篇关于Flutter-自定义按钮点击区域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!