Is there a way in Flutter to catch the "start-moving" event in a Dismissible Widget? - flutter

I am using the Dismissible widget to be able to remove certain screens/widgets from a flutter app by swiping them up.
What I need to achieve is to blur the image once the user starts swiping/dismissing them but the widget only has the "onDismissed" callback, but does not offer a way to catch the swiping event.
Any alternatives?

You can achieve That using the GestureDetector widget
// This is the sample
GestureDetector(onPanUpdate: (details) {
if (details.delta.dx > 0) {
// swiping in right direction
}
});
You can check there are many events that you can trigger like onHorizontalDragUpdate, and many more you can check out.

Related

How to tap all items of a list or a grid in a Flutter widget test?

In my Flutter widget tests I want to tap all (or first n) items in a list or grid view.
I already came up with a solution and although it seems to work, it looks overly complicated to find the tap target again by key:
for (final element in find.byType(ListTile).evaluate()) {
await tester.tap(find.byKey(element.widget.key!));
}
Is there a more elegant way to do it?
You can tap at a certain location on the widget:
e.g. tapping at center of the widget
for (final element in find.byType(ListTile).evaluate()) {
await tester.tapAt(tester.getCenter(find.byWidget(element.widget)));
}

Flutter GestureDetector onTapRight & ontapLeft

i have read the flutter documentation about GestureDetector and i can only see onTapDown &
onTapUp
and i believe if there is up and Down there will be Right and Left
how can i achieve onTapRight and onTapLeft
onTapDown & onTapUp do not refer to the area/position where you press, but they do refer to:
onTapDown: The moment your finger actually touch the screen
onTapUp: The moment your finger leave the screen
From the docs:
onTapDown: A pointer that might cause a tap with a primary button has contacted the screen at a particular location.
onTapUp: A pointer that will trigger a tap with a primary button has stopped
contacting the screen at a particular location
To achieve right or left tap, you could use a Stack widget to overlay a row with 2 Gesture dector widgets.
DOCS:
onTapDown
GestureTapDownCallback
thanks to #L.Gangemi that gave me the idea of what to use....
i solved this by this sample code
onTapUp: (details) {
if (details.localPosition.direction >
1.0) {
print('Left');
}
if (details.localPosition.direction <
1.0) {
print('Right');
}
},

How to absorb swipe motion only in Flutter

I am looking for a widget, analogous to AbsorbPointer, that would absorb swipe motions. The goal is to allow "tap" actions to go through to the child but let the parent handle the "swipe" motions.
If possible I would like to also differentiate absorption depending on direction (only absorb vertical motion for example).
Thank you for your help,
you can use GestureDetector to detect tap behavior and swipe motions
GestureDetector(
child: Widget(), // your widget
onTap: () { // Tap behavior listener
// your tap logic
},
onHorizontalDragUpdate: (DragUpdateDetails details) { // Swipe behavior listener
print(details.primaryDelta); // Positive is left to right, Negative is right to left
// your swipe logic
},
)
using two GestureDetector you can warp the parent with listener onHorizontalDragUpdate to detect the swipe motion while warping the child with listener onTap to detect the tap behavior

How switch from GridView to ListView on click of a button in flutter?

I am building a wallpaper app and want to implement a feature of switching views, like switching from GridView to ListView on the press of an IconButton in FLutter
would look something like this:
The only way I could think of implementing this feature is by changing the crossAxisCount value in the GridView.count() method by hooking up a counter to the crossAxisCount property and controlling it through a function on click of an IconButton, this works but I have to Hot Reload my application every time the counter is incremented or decremented,
Any Suggestions or fix to this problem is welcomed.
You can simply use ternary operators and setState() to achieve what you want.
First, declare a boolean above your widget build. Then you can use ternary operators to change it from gridview to listview.
bool isGridView=true;
#override
Widget build(BuildContext context) {
Scaffold(
body: isGridView ? GridView.builder():ListView.builder(),
);
}
In your onPressed(), you can call setState():
setState(() {
isGridView=false;
});

How to dismiss flutter dismissable widget programmatically?

Is it possible to dismiss dismissable programmatically? Not by swipe, but by let's say button click.
The only thing that comes in mind is imitating gesture event with a certain velocity, but this sounds horribly wrong.
How about considering an AnimatedList instead.
A scrolling container that animates items when they are inserted or removed.
This widget is similar to one created by ListView.builder.
Please try this.
key: Key(UniqueKey().toString()),
2nd Way
onDismissed: (DismissDirection direction) { dismissViewList(ObjecClass); }
And function is :
dismissViewList(ObjecClass) {
if (_personList.contains(ObjecClass)) {
//_personList is list of ObjecClass shown in ListView
setState(() {
_personList.remove(ObjecClass);
});
}
}