Pretty_Girl
Pretty_Girl

Reputation: 327

The `gesture detector` does not work, and it does not produce any error

The gesture detector does not work, and it does not produce any error, it just does nothing when I click the widget ToolSetRight, I'm passing data to the ToolSetRight widget, can that be a reason that it doesn't work?

children: <Widget>[
            GestureDetector(
              onTap: () {
                print('button');
                
              },
              child: ToolSetRight(
                icon: Icon(
                  Icons.home,
                ),
                width: 35,
                height: 35,
                 
              ),
            ),

EDIT: the ToolSetRight as follows

 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)),
              ),
            ),
          ),
        ),
      )
    ],
  ),

Upvotes: 0

Views: 352

Answers (1)

Raine Dale Holgado
Raine Dale Holgado

Reputation: 3460

The reason GestureDetector didnt work is because it doesnt know where it got pressed on Inkwell or GestureDetector widget. Removed the parent GestureDetector Widget and call the onTap in the ToolSetRight.

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,
  ),

Upvotes: 1

Related Questions