Flutter How to partially block touch event inside GestureDetector - flutter

I have a listview with every Item wrap inside a GestureDetector to be clickable, but is there a way to have a portion of the Item view to be not clickable? Thanks
GestureDetector(
onTap: () {
...
},
behavior: HitTestBehavior.opaque,
child: Column(
children: <Widget>[
child: SizedBox( height: 40,
child: Container(
color: Colors.green,
child: Text("Hello world"), // want to make the text area not clikable
),
),
someOtherWidgets...
],
),

Yes then you have to take particular item click and it should be blank in that case, Example InkWell click and child Text
InkWell(
onTap: () {
...
},
behavior: HitTestBehavior.opaque,
child: Column(
children: <Widget>[
child: SizedBox( height: 40,
child: Container(
color: Colors.green,
child: GestureDetector(
onTap: (){}
,
child:Text("PBX",style: TextStyle(fontSize: 15.0),)), // you can use like this text will be blank click
),
),
someOtherWidgets...
],
),

Related

Do not close ontap inside tooltip

How to have interactions inside a tooltip?
By default, as soon as you tap inside, it closes the toolip, except I would like to have clickable links for example:
Tooltip(
height: 50,
padding: const EdgeInsets.all(80),
richMessage: makeTooltip(context, issuerAddress, issuerName),
child: Text('Hover me'));
InlineSpan makeTooltip(BuildContext context, String address, String name) {
return WidgetSpan(
child: Column(
children: [
GestureDetector(
onTap: () {
Clipboard.setData(ClipboardData(text: address));
},
child: Text(
address,
),
),
const SizedBox(height: 5),
Text(name),
]),
);
}
Currently GestureDetector does not work, tooltip closes instead.
Have you tried using the GestureDetector with a Material? I'm assuming you want the tooltip to be dismissible as well.
child: Column(
children: [
GestureDetector(
onTap: () {
Clipboard.setData(ClipboardData(text: address));
},
child: Material(
child: InkWell(
child: Text(
address,
),
),
),
),
const SizedBox(height: 5),
Text(name),
]),
);

How to disable tap on the inner child of the InkWell?

I have this widget
InkWell(
onTap: (){
// clicks overAll
},
child: Column(
children: [
Text('Sample one'),
SizedBox(),
Text('Sample two'),
AnotherWidget(),
AnotherWidget2(),// want to disable click only this widget
],
),
);
I want to disable the click only to the AnotherWidget2() widget. but Inkwell not allowing that even If I use IgnorePointer on the AnotherWidget2()
I know that I can put InkWell individually on every widget except AnotherWidget2(). But Is there any way to acheive without putting InkWell on individual widgets?
Try below code hope its help to you. Wrap your AnotherWidget2() with InkWell() and set onTap()=>null
InkWell(
onTap: () {
// clicks overAll
print('clicks overAll');
},
child: Column(
children: [
Text('Sample one'),
SizedBox(),
Text('Sample two'),
Container(
height: 100,
width: 200,
margin: EdgeInsets.all(10),
color: Colors.red,
),
InkWell(
onTap: ()=> null,
child: Container(
height: 100,
width: 200,
margin: EdgeInsets.all(10),
color: Colors.blue,
),
),
],
),
),

Add a button with a size and add icon inside it in flutter

I am trying to add an icon to a button.
What steps I followed: Created an icon button filled in the properties.
After this, I wrapped it in a container because I don't want my button to be big.
Here is the image of what I am getting: [![enter image description here][1]][1]
I want that Icon to be fit inside the button,I even tried to wrap the child with centre but still the same results.
My Code Snippet:
Container(
height:18,
width:20,
decoration:BoxDecoration(
border:Border.all(color:Colors.orangeAccent,width:1),
shape:BoxShape.rectangle,
),
child:Centre(child:IconButton(
icon:Icon(Icons.add,
size:16,
color:Colors.orange,),
onPressed:(){},
),),
You can try this code block
Container(
width: 50,
height: 50,
child: FlatButton(
onPressed: () {},
child: Row(
children: [
Icon(Icons.ac_unit),
Text('Add More')
],
),
),
)
The easiest way you can do like below code.
Container(
width: 50,
height: 50,
child: GestureDetector(
onTap: () {},
child: Row(
children: [
Icon(Icons.ac_unit),
Padding(
padding: EdgeInsets.only(left: 10),
child: Text('Add More'),
)
],
),
),
)
You can use TextIconButton instead of IconButton.

How to make a row clickable? Flutter

I want to make this row clickable to redirect to a different page, how should I do it?
There are a bunch of these rows in the code.
body:
Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
Container(
padding: EdgeInsets.all(10.0),
color: Colors.white,
),
Row(
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
Container(
padding: EdgeInsets.fromLTRB(10,16,0,16),
color: Colors.white,
child: Icon(Icons.favorite),
),
Container(
padding: EdgeInsets.fromLTRB(5,20,140,20),
color: Colors.white,
child: Text('Favoritos'),
),
Container(
padding: EdgeInsets.fromLTRB(145,16,5,16),
color: Colors.white,
child: Icon(Icons.keyboard_arrow_right),
),
],
),
You can wrap your widget with GestureDetector or InkWell like this:
GestureDetector(
onTap: (){
// Add what you want to do on tap
}
child: Row(
// Add your properties here
),
),
InkWell(
onTap: (){
// Add what you want to do on tap
}
child: Row(
// Add your properties here
),
),
To make the row clickable you will have to wrap it to either inkwell or GestureDetector, else you can chose IconButtons.
InkWell(
onTap: (){ print("Card Clicked"); }
child: Container(
padding: EdgeInsets.fromLTRB(10,16,0,16),
color: Colors.white,
child: Icon(Icons.favorite),
),//Container
);
To go to different activity onTap try this code inside onTap():
onTap: (){
print("Card Clicked");
Navigator.push(
context,
MaterialPageRoute(builder: (context) => SecondRoute()),//secondRoute is the
//second class you want to go to.
}
You can use hardik's answer if you want to make clickable columns. Hope it helps! Happy coding:)

How to add two parameter within sized box in flutter?

I wanted to change the size of the raised Button..
So i created a sized box and added width and height as I wanted and wrapped the raised button inside the sized box...
After I did that the button sticks to the left corner only..
So I used the align widget to keep it in center but since I made to child under the sized box it became an error..
So how to rectify this?!
SizedBox(
width: 100.0,
height: 50.0,
child: Align(
alignment: Alignment.center,
),
child: RaisedButton(
child: Center(child: Text("Sign Up", style: TextStyle(color: Colors.white.withOpacity(.7)),)),
color: Colors.blue[800],
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(builder: (context)=> UserPage()));
}
),
)
try like this,
SizedBox(
height: 50.0,
child: Row(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
RaisedButton(
child: Center(
child: Text(
"Sign Up",
style: TextStyle(color: Colors.white.withOpacity(.7)),
)),
color: Colors.blue[800],
onPressed: () {
Navigator.push(context,
MaterialPageRoute(builder: (context) => UserPage()));
}),
],
),
)
Simply wrap with center widget
Center(
child: SizedBox(
width: 100.0,
height: 50.0,
child: RaisedButton(
child: Center(child: Text("Sign Up", style: TextStyle(color: Colors.white.withOpacity(.7)),)),
color: Colors.blue[800],
onPressed: () {
}
)
),
)