Flutter: OnTap and OnPressed Same Inkwell - flutter

Currently I have an Inkwell and an onTap that does x when tapped on, which is what I want. On top of that, I would like it to do y instead of x when a user presses and holds that button for a second or two.
I was wondering what functionality I can use in order to implement this, thanks in advance for any help!
InkWell(
splashColor: Colors.black,
highlightColor: Colors.blue,
onTap: pageX,
child: Container()

Inkwell supports onTap and onLongPress.
Example:
child: InkWell(
onTap: (){print("onTap!")},
onLongPress:(){print("onLongPress!")},
}

Related

inkwell ontab does not work when clicking on the form

I use the searchField, judging by the documentation, there should be an onTab field in the searcField widget, but apparently the library has been updated and there is no such function anymore, since I need to trigger an event in the block when clicking on the field, I decided to wrap the widget in inkwell, but when clicked, nothing works and the event does not called
BlocBuilder<FillprofileBloc, FillprofileState>(
builder: (context, state) {
return InkWell(
focusColor: Colors.transparent,
onTap: () {
_bloc.add(OnCitySearchTabEvent());
},
child: SearchField(
searchInputDecoration: InputDecoration(
There is a workaround with GestureDetector.
GestureDetector(
behavior: HitTestBehavior.translucent,
onPanDown: (_) {
debugPrint("pan down");
},
child: SearchField(),
),
You can use onTap param of TextField itself here. Or wrap your TextField with IgnorePointer to use InkWell

I try to navigate page through clicking an image

I am new to flutter. Im trying to navigate page through clicking an image but it keep messing around.
below show before and after i make changes
you can use inkwell
inkwell has so many property like color etc.....
it's a rectangular area of a Material that responds to touch.
InkWell(
splashColor: Colors.transparent,
highlightColor: Colors.transparent,
focusColor: Colors.transparent,
hoverColor: Colors.transparent,
onTap: () {
Navigator.pushReplacementNamed(context, "/you'r destination page");
},
child: Image.asset(" you'r image path ")
)
it provides tapping section , using onTap you can tap what ever you want
OR
you can use GestureDetector
GestureDetector(
onTap: () {
Navigator.pushReplacementNamed(context, "/you'r destination page");
},
child: Image.asset(" you'r image path ")
)
it also recognize gestures that correspond to its non-null callbacks.
You need to wrap your Image with the gesture detector, right now they are in the same column but not together ie
GestureDetector(
onTap: DoNavigationHere,
Child: Image.asset
)

Why isn't GestureDetector working in flutter?

Gesture Detector isn't working - why not?
print or Navigator not working
GestureDetector(
onTap: () {
... ;
},
child: Container(
color: Colors.white,
width: 170,
height: 60,
child:...
),
),
Often times, this is because your GestureDetector is a child of another Widget that has an onTap property. For example, if you give an ElevatedButton a child of GestureDetector, this GestureDetector's onTap is never reached, due to the ElevatedButton overruling its onTap property.

Flutter Box with Navigation on pressed

I am writing a flutter app where i want create boxes like grid and each can be click to navigate on different screen.
Similar to below example
I am a beginner, how can i achieve this. Can you please share some pointer. I went through Documentation but if you can help me with what to search for I can read. or if you can share some exmaple.
You can wrap each box widget with an inkwell and add an onTap to it where you can call the navigation ie:
InkWell(
onTap: () => Navigator.of(context).pop(false),
child: Container(
height: 25.0,
width: 80.0,
child: Text('CANCEL'),
),
InkWell
Gesture Detector

How can I implement tap-able Text widget, Flutter?

I have a Text widget on pressing which another Route has to be shown. But I could not see any onPressed() method for the Text widget. Please Help.
In your case there are multiple routes where you can go.
Using material TextButton:
TextButton(onPressed: () {}, child: Text('Your child'))
Using InkWell Widget, which covers your widget with 'as button' properties, splashes etc, which allows you to have more customisable buttons taps:
InkWell(onTap: () {}, onDoubleTap: () {}, onLongPress: () {}, onHover: () {}, ..etc , child: Text('Your child widget'))
Using GestureDetector, is the most customisable solution for any gestures you can provide (from its name), can handle taps, long presses, double taps, drags etc.
Syntax is similar:
GestureDetector(onTap: () {}, child: Text('Your child widget'))
Try using TextButton widget:
TextButton(
onPressed: () {},
child: Text('Simple Button'),
),
The best way to make any widget tappable is to use GestrureDetector you just put it outside of the widget/widgets you want and you can use dozen of properties.
For example
GestureDetector(child:
onPressed: () {},
Text('Your text')
)