I was wondering if it is possible to have a Dismissible widget which does one thing if dragged for less than 25% of the screen and does something else if dragged more than 25% of the screen.
In the example below the first onDismissed function would trigger if the tile was dismissed in the red part and the other onDismissed function would trigger if it was dismissed in the grey part.
No, we don't have any widget like that you want.
You have to create what you want with GestureDetector()
Related
I have an AnimatedSlide widget as a child of a column. Depending on a simple condition, it should slide between its initial and a destination position. This works just fine.
The problem is that the AnimatedSlide widget has an InkWell as one of its children. The InkWell's onTap callback works as intended if the AnimatedSlide widget is in is initial position. However, in the destination position, nothing happens when tapping the InkWell.
It seems like the hitbox disappeared completely because even tapping the initial position doesn't do anything.
Is there any way to get this working or is AnimatedSlide simply not meant to be used with InkWells, Buttons, etc.?
I've been trying to make Bookmark button's onTap work because it was working only sometimes.
I'm using the Expanded widget in the Bookmark button but when I toggle debug point on, I saw that its area is shrunk and that's why taps are not working. I give this widget size and added HitTestBehavior.translucent on GestureDetector but no luck.
Any idea how I can fit this button without losing its tap area?
I have a ScrollablePositionedList and want to do stuff when the next Widget in the List is scrolled to. How can I detect that? I have tried with NotificationListener and ScrollUpdateNotification but only saw the option to use the height of each widget which is flexible and it would be kinda ugly to do it like this. Is there a better way? Like see the pixel height of a widget or is there a function I could use?
You should be able to monitor what items are visible on screen with:
itemPositionsListener.itemPositions.addListener(() => ...);
Then, based on this. you can see whenever there is a change, whenever a new item is scrolled to / appears in the list. then make whatever changes you want
Here is the documentation for more info
How can I combine a swiper action with a fade-in/fade-out action in another area of the screen?
My screen is divided into two halves: The Top is a text widget and the bottom is a swiper widget with two pages. My goal is to fade-out the text in the top half when I swipe to the second page in the bottom half.
I'm using this dependency for the swiper widget in the bottom half: https://pub.dev/packages/flutter_swiper
I solved it by using GestureDetector widget and updated the opacity via the state.
The GestureDetector needed two functions: onDragUpdate and onDragEnd. Both changed the state of the progress which is also used to update the opacity in the other half.
Quite some work for such a small interaction, however, it works.
I have an "add" floating action button in Scaffold. When clicking the "add" floating action button, it will create two more floating action buttons above the original floating action button so that the user can choose which floating action button to click.
When the two more floating action buttons are active/popup, I want the entire screen to go blur/dark and inactive, similar to the effect to call showDialog(). So that only the three floating action buttons are active and all other screen parts are inactive and dark/blur.
And finally by clicking the inactive area, the two floating action buttons will be dismissed.
Thank you very much for your help.
I found two ways to achieve this.
With PopupRoute
I read flutter framework code and found out showDialog is actually using PopupRoute. Basically, this will create a new route and make the previous routepage inactive.
The simplest code is as follows:
class MyPopupRoute extends PopupRoute<void> {
#override
Color get barrierColor => Colors.black54;
#override
bool get barrierDismissible => true;
#override
String get barrierLabel => "Close";
#override
Widget buildPage(BuildContext context, Animation<double> animation, Animation<double> secondaryAnimation) => MyPopupPage();
#override
Duration get transitionDuration => const Duration(milliseconds: 300);
}
where MyPopupPage is the new popup widget.
If you want animations, you can override the method buildTransitions method. Simply check the API doc for more detail.
With Overlay
Thank #01leo very much for providing this way. The Flutter Challenge: Feature Discovery video has detail explanation on how to use it. Basically, just use Overlay.of(context).insert(overlayEntry); and the overlay is like a hidden stack on the top of the current page built-in.
At the time I am writing this answer, the code provided by the video author is not working in the latest fluter (dart 2). You have to wrap the overlay insert in a Timer such as Timer.run(() { Overlay.of(context).insert(calendarOverlay);}); to workaround the problem and make the code run.
By my findings, the reason why the author needs an async function call for overlay insert is because it couples the creation of overlay and the normal widget in a stateful widget. And when the state changes, the overlay insert will be called before building the child's widget and overlay needs to know the child's position but the child's widget is not created yet. If you don't want to async call overlay insert, you can simply decouple the creation of overlay and the corresponding normal widget. In such a way, you can simply call overlay insert normally. But with this sync way, you may not be able to find the normal widget position easily though.
(Btw, I use the word "normal widget" here, but it's not very correct. I haven't found a proper English word for it.)
I can't provide any code, but showDialog() and similar methods use the Overlay, integrated in Scaffold. It can be accessed by using Overlay.of(context). It essentially is a Stack around the whole Scaffold and you can insert items on top of everything.
For a more in-depth look into the Overlay and code examples I recommend watching this Flutter Challenge: Feature Discovery