GestureDetector motion related to width? - flutter

I have a GestureDector wrapping a Container.
I am trying to do some logic based on where motions land relative to the total width of the GestureDetector. But I do not know the width ahead of time, so there is no way I can do this logic.
What is the proper way to go about achieving this in flutter?

Related

Cant find the right widget combination, if it exists

I have an Image (which is a map), that I want to always fill its container, but keeping its aspect ratio.
I put it inside an InteractiveViewer, so it can be zoomed and panned.
When the interactiveviewer zoom level is minimum(1) the whole width of the image must fit the container, and if the height does not fit, It should be possible to pan.
I tried many combinations of widgets, but could not find the right one for this behavior.
Can anyone with more flutter experience help?
Best Regards
I was able to solve it by using constrained=false in the InteractiveViewer widget

Flutter increase performance of large number of Positioned Widgets on screen

I'm making a grid of hexagons by placing Positioned Widgets. I have them inside an Interactive Viewer Widget so I can zoom in and out and move around.
Issue I'm having however is that with a large number of them being rendered it's far too laggy. It's unusable with about 4000 rendered on screen and ideally I need 10s of thousands. And this has nothing to do with the Widget itself as it's the same when replaced with a SizedBox with a Container or Text in.
I am using an InteractiveViewer.builder and only render the Widgets on the screen, which works great and there's no lag when zoomed in with few widgets on the screen, however I need to zoom out and see more.
I've also run in release mode and it's the same. I'm running in Windows and my PC is more than capable, too capable compared to the phones this should also be able to run on.
Is there some way to increase performance, or some other way I should be doing this instead of thousands of Positioned Widgets? Or is Flutter just not suited for this?
Edit: Image.
Using a widget for each individual hexagon at that scale feels like massive overkill. If you're going to use flutter, maybe use a CustomPaint widget, which allows you to draw shapes directly to a pixel grid?
You could wrap it in a GestureDector and implement scrolling and zooming via that perhaps?

How would you make this simple flutter layout responsive?

A year has passed since last time I had to use flutter to build a little app for my firm. At that time MediaQuery was the trending way to create layouts ready for every screen size.
Today I am trying to build a simple layout like this one:
The part I am concerned about is the 3 circles in the middle. They have an icon and text inside and must be positioned at the positions seen in screen.
So, I have been investigating a bit how to create that part of the layout in a responsive way. I mean, that the circles are positioned at the correct position and size relative to the screen size and that the icon and text inside the circle are positioned and resized correctly too ,to avoid overflowing the circles.
Is the MediaQuery class still the only tool that can be used to build this kind of responsive layouts? Would you tackle this layout using a different method?
Yes MediaQuery is still heavily used, but Flutter has introduced some good widgets based on Orientation and Responsive Layouts:
OrientationBuilder - Builds different widget trees based on Orientation - For Example if the device is horizontal, you might see a Square instead of a Circle.
CustomMultiChildLayout - It can automatically decide how to size and position each child, as well as size the parent. Single widgets can be used CustomSingleChildLayout
Also when resizing text automatically I found Auto Size Text to be amazing

Flutter: Creating a scroll view that contracts center item before allowing the list to scroll

I'm creating a scroll view that pads that center item with some extra space vertically. I want to accomplish two things:
1- Shrink the center item's padding at the same rate the user is moving his finger. For example, if the padding of the center item is 50 pixels and the user moved his finger for 10 pixels then I would like to decrement the padding to 40.
2- I would like to stop the list view from actually scrolling until the padding for the center item is 0. The list view should scroll as normal once the center item's padding is 0.
I'm a little lost here. I've been trying playing around with implementing my own ScrollController and ScrollPhysics but I haven't been able to achieve exactly what I'm looking for. I also saw that there was a class in Flutter called ScrollPosition that controls the position for each scrolling widget but I haven't been able to figure out how to use these to accomplish the behavior I'm looking for.
Could someone point me in the right direction?
Change the physics property of the ListView, NeverScrollablePhysics() doesn't allow scrolling.
Maybe use a GestureDetector for detecting the swipes.
Be careful of the placement of this widget though.
It can interfere with the normal scrolling of the listView.
Try experimenting with the animationController instead of calling setState() multiple times,
it's wasteful to refresh the screen multiple times just to change the padding.

Flutter: How to create a CustomScrollView with items vanish/appear smoothly

I want a CustomScollView with flexible Header where the items while scrolling vanish/appear smoothlyt by overlaying the top and bottom limit of the SliverList with a gradient that ranges from transparent to the color of the rest of the page.
Like in the this schematic layout.
At the bottom this was possible without any problems by placing the Container with the gradient inside a Stack with overlap=true and positioning it outside the Stack.
I tried the same inside the SliverAppBar's flexiSpace but it did not allow that the gradient container overlapped its limits instead it was clipped.
Is there an easy way to accomplish it? I found a solution by using a Stack around everything and position the gradient container there by listening to the moving of the flexispace but that seems a bit cumbersome.