"手势检测器"不工作,它不产生任何错误



gesture detector不工作,它不产生任何错误,当我点击小部件ToolSetRight时,它什么也不做,我是passing dataToolSetRight小部件,这可能是它不工作的原因吗?

children: <Widget>[
GestureDetector(
onTap: () {
print('button');

},
child: ToolSetRight(
icon: Icon(
Icons.home,
),
width: 35,
height: 35,

),
),

编辑:ToolSetRight如下

Stack(
alignment: Alignment.center,
children: <Widget>[
SizedBox(
width: widget.width,
height: widget.height,
child: ClipRRect(
borderRadius: BorderRadius.circular(radius),
child: Container(
child: Material(
color: Color(0xff0D8EEB),  
child: InkWell(
splashColor: Colors.white,
onTap: () {

},
child: SizedBox(
width: widget.width,
height: widget.height,
child:
FittedBox(fit: BoxFit.contain, child: widget.icon)),
),
),
),
),
)
],
),

GestureDetector不工作的原因是它不知道它被按在Inkwell或gestredetector小部件上的位置。删除父GestureDetector Widget并调用ToolSetRight中的onTap。

class MyWidget extends StatefulWidget {
@override
_MyWidgetState createState() => _MyWidgetState();
}
class _MyWidgetState extends State<MyWidget> {
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: ButtonT(
onTap: () {
print("Pressed");
},
),
),
);
}
}
class ButtonT extends StatefulWidget {
final VoidCallback onTap;
const ButtonT({Key key,required this.onTap}) : super(key: key);
@override
_ButtonTState createState() => _ButtonTState();
}
class _ButtonTState extends State<ButtonT> {
@override
Widget build(BuildContext context) {
return InkWell(
onTap: widget.onTap,
child: Container(
child: Text("pResss"),
),
);
}
}
ToolSetRight(
ontap: (){
print("On pressed");
}
icon: Icon(
Icons.home,
),
width: 35,
height: 35,
),

最新更新