sajanyamaha
sajanyamaha

Reputation: 3198

onTap() of InkWell not triggering

Also tried onPressed() IconButton , not printing . Tried IgnorePointer as well , no change , interesting thing is onLongPress() is working .is it because inside a container .This green button am talking about.

enter image description here

                              Container(
                                  height: 50,
                                  width:50,
                                  padding: const EdgeInsets.all(15.0),
                                  decoration: BoxDecoration(
                                      color: myGreen, shape: BoxShape.circle),
                                  child: InkWell(
                                    child: Icon(
                                      Icons.send,
                                      color: Colors.white,
                                    ),
                                    onTap:(){
                                      print("sdsdsd");
                                      //sendChatToFirestore();
                                    },
                                    onLongPress: (){
                                      print("long press");
                                    },

                                  ),
                                )

Upvotes: 1

Views: 1366

Answers (2)

LonelyWolf
LonelyWolf

Reputation: 4392

Try this. Instead of creating mess with multiple widget you can use out of the box FAB which do the same thing

FloatingActionButton(
        onPressed: () {
          print("sdsdsd");
          //sendChatToFirestore();
        },
        backgroundColor: Colors.green,
        child: Icon(
          Icons.send,
          color: Colors.white,
        ),
      ),

Or if you want a more control over the button use simple FlatButton

FlatButton(               //change to RaisedButton to be raised
          onPressed: () {
            print("sdsdsd");
            //sendChatToFirestore();
          },
          onLongPress: () {
            print("long press");
          },
          padding: EdgeInsets.all(16),
          shape: CircleBorder(),
          color: Colors.green,
          child: Icon(
            Icons.send,
            color: Colors.white,
          ),
        ),

There is no need to reinvent the wheel for such simple widget

OUTPUT

enter image description here

Upvotes: 1

Ajil O.
Ajil O.

Reputation: 6892

Ink well renders a ripple animation when inside a Material widget. You can set most of the customizations you would normally give to a Container here as well. Wrap a material widget around your inkwell and you are done.

Container(
  height: 50,
  width:50,
  padding: const EdgeInsets.all(15.0),
  decoration: BoxDecoration(
    color: myGreen, shape: BoxShape.circle),
    child: Material(child:                  // <- This is the magic widget
        InkWell(
          child: Icon(
          Icons.send,
          color: Colors.white,
        ),
     ),
      onTap:(){
          print("sdsdsd");
          //sendChatToFirestore();
      },
      onLongPress: (){
          print("long press");
      },
   ),
)

But as mentioned in other answers and comments, probably going for a pre-built widget makes more sense in this case. Unless of course, you need to set up your own gesture detection system for the widget

Upvotes: 0

Related Questions