I’ve faced a problem with scrolling on my flutter application. I’ve created a widget with SingleChildScrollView
as a top of the widget in the tree. Then I’ve added GestureDetector
to manipulate over my map. Rest of the screen will contain a simple column or text (but a lot of them so I need to scroll). This is a simple layout I want to achive Desired layout.
Pseudocode:
SingleChildScrollView(
child: Column(
children:[
ScreenTitle("Title"),
GestureDetector(child: Map()),
Text("Lorem ipsum"),
Text("Lorem ipsum"),
...
]
)
);
The problem is with the scroll priority. When I tap horizontly on Map widget everything works, but if I tap vertically, SingleChildScrollView catch this gesture and scroll entire page. I want to catch all gesture for my Map and only if user tap somewhere else it should be delegated to SingleChildScrollView.
Of course without SingleChildScrollView, my GestureDetect works fine but… the text is behinde the visible area.
I want to catch every Gesture on my map widget and delegate to SingleChildScrollView only events not from Gesture.
I tried to remove SCSV and replaced it by ListView (the same problem).
2
Answers
If you want your map to be independent from your
SingleChildScrollView
then extract it out of it, like this:It’s important to wrap the
SingleChildScrollView
withExpanded
because other wise you will get render errors.To achieve the desired layout, you can wrap your
Column
widget inside aListView
widget. TheListView
will allow you to scroll through the column’s children, and theGestureDetector
will allow you to manipulate the map.Here’s an example of how you can achieve the desired layout: