How to make a row clickable? Flutter - 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:)

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

How to overlap button on BottomSheet in Flutter?

In my design, there is a close button in the BottomSheet. I have tried Stack. But it didn't work. Does anyone know how to achieve the result? Thanks :)
modalBottomSheet(context) {
return showModalBottomSheet(
context: context,
builder: (context) {
return Stack(
children: [
Container(
child: Text('Sample Text'),
),
Container(
height: 50,
width: 50,
decoration: BoxDecoration(
color: Colors.red,
shape: BoxShape.circle,
),
),
],
);
}
);
}
So I've been trying around for a bit, and this seems to work as you explained.
modalBottomSheet(context) {
return showModalBottomSheet(
context: context,
builder: (context) {
// using a scaffold helps to more easily position the FAB
return Scaffold(
body: Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
SizedBox(
width: double.maxFinite,
),
Padding(
padding: EdgeInsets.all(30.0),
child: Text("Text in the sheet"),
),
],
),
// translate the FAB up by 30
floatingActionButton: Container(
transform: Matrix4.translationValues(0.0, -30, 0.0), // translate up by 30
child: FloatingActionButton(
onPressed: () {
// do stuff
print('doing stuff');
},
child: Icon(Icons.add),
),
),
// dock it to the center top (from which it is translated)
floatingActionButtonLocation: FloatingActionButtonLocation.centerTop,
);
});
}
The meat of the solution here is to transform the Container which contains the FAB. I got this idea from this older SO answer to a somewhat related question.
The result looks like this:
You'll probably have to make some more edits to achieve the exact result you desire, but I hope this sets you on the right path.
Edit
When, in the above solution, you want to press the FAB, and you tap the top half, the onPressed handler fires, but the modal also closes. You should probably use a WillPopScope that only pops when the actual button is pressed (and not the area around/above it). If you think it's fine pressing anywhere above it as well, you can just leave it as-is.
showModalBottomSheet(
backgroundColor: Colors.transparent,
context: context,
builder: (BuildContext context) {
return Stack(clipBehavior: Clip.none, children: [
Container(
decoration: const BoxDecoration(
color: Colors.white,
borderRadius:
BorderRadius.vertical(top: Radius.circular(20))),
height: 220.h,
child: Padding(
padding: const EdgeInsets.symmetric(
horizontal: 10.0, vertical: 16),
child: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
ElevatedButton(
color: Colors.green,
onPressed: () {},
child: const Center(child: Text('Remove')))
],
),
),
),
),
Positioned(
top: -30.h,
right: 12.w,
child: FloatingActionButton(
onPressed: () {},
child: const Icon(Icons.close),
)),
]);
},
)

How to remove the background when clicking on the text of a link?

I have a Text widget with a link to another screen, when clicked, the background appears. How do I remove the background when clicked?
More in the photo
Align(
alignment: AlignmentDirectional.topStart,
child: FlatButton(
//color: Colors.redAccent,
onPressed: () => Navigator.of(context).push(
new MaterialPageRoute(builder: (context){
return new SettingPage();
}
),
),
padding: EdgeInsets.only(left:20.0),
child: Row(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Padding(
padding: const EdgeInsets.all(8.0),
child:SvgPicture.asset(iconSvgS5, height: 30.0, color:Colors.blueAccent),
),
Padding(
padding: const EdgeInsets.only(left:20.0),
child: GestureDetector(
onTap: () => Navigator.push(
context,
MaterialPageRoute(builder: (context) => FaqPage()),
),
child:Text(
"Вопросы и ответы",
style: TextStyle(
fontSize: 18.0
),
),
),
),
],
),
),
If you are wrapping your text widget inside of a button then the button by default have feedback to let users know when they are pressed, if you don't need the feedback consider wrapping the button with a GestureDetector widget, and passing a function to the onTap property
Removed the background color on click with this code:
splashColor: Colors.transparent,
highlightColor: Colors.transparent,
You can use the hoverColor property of the FlatButton to set the hoverColor to your liking, here is the modified code that disables the hoverColor (simply sets it to transparent Colors.transparent) -
Align(
alignment: AlignmentDirectional.topStart,
child: FlatButton(
//setting the hover color to transparent.
hoverColor : Colors.transparent,
onPressed: () => Navigator.of(context).push(
new MaterialPageRoute(builder: (context) {
return new SettingPage();
}),
),
padding: EdgeInsets.only(left: 20.0),
child: Row(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Padding(
padding: const EdgeInsets.all(8.0),
child: SvgPicture.asset(iconSvgS5,
height: 30.0, color: Colors.blueAccent),
),
Padding(
padding: const EdgeInsets.only(left: 20.0),
child: GestureDetector(
onTap: () => Navigator.push(
context,
MaterialPageRoute(builder: (context) => FaqPage()),
),
child: Text(
"Вопросы и ответы",
style: TextStyle(fontSize: 18.0),
),
),
),
],
),
),
),
Also side note having a GestureDetector inside of a FlatButton is redundant, and in your case it is ambiguous as well since they are do two separate navigation.
Set all color properties of the FlatButton to transparent.
The example below also includes a convenient hack, how to make the clickable area wider, so if the user will press near the icon, the button will work.
It improves button responsiveness.
Example
FlatButton(
color: Colors.transparent,
focusColor: Colors.transparent,
hoverColor: Colors.transparent,
highlightColor: Colors.transparent,
splashColor: Colors.transparent,
padding: const EdgeInsets.all(0.0),
minWidth: 24,
onPressed: () => Get.back(),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(
CupertinoIcons.clear,
color: Theme.of(context).colorScheme.pureBlack,
size: 18,
),
],
),
),

Flutter How to partially block touch event inside GestureDetector

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