-
I have a map with a card that floats on top of that map. Inside of the card, I have a ListView that you can scroll through. Here's the problem: Everything works great until I reach the end of the scroll, at which point it starts zooming in/out the map below it. I have tried everything I could think of to try to prevent this behavior but I can't figure out how to stop the scroll event from propagating from the listview into a zoom... It seems like no matter what I attempt to do, when the list view can't scroll anymore flutter_map is taking over and the scrolls start becoming zoom in/out instead behind the card. Has anyone experienced this before and can offer some help? I'm straight out of ideas. This is Flutter 3.27.3, |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 7 replies
-
Could you post a showcase video and some code of your implementation please? |
Beta Was this translation helpful? Give feedback.
-
Here is a small video. The code is a little harder because it's part of a much larger application but essentially I have this:
As you can see in the video the list view behaves properly until I hit the overflow up/down, at which point the map starts zooming in/out - the behavior I want is at the end of the list additional scrolling does nothing. Screen.Recording.2025-02-08.at.2.39.32.PM.mov |
Beta Was this translation helpful? Give feedback.
-
I have. |
Beta Was this translation helpful? Give feedback.
-
I have another hack that might be more preferable because it's a drop-in solution for many situations, feel free to adapt it to your needs. I put a huge invisible scrollable widget behind the main content and use a There's also a import 'package:flutter/material.dart';
import 'package:flutter_map/flutter_map.dart';
import 'package:latlong2/latlong.dart';
import 'package:transparent_pointer/transparent_pointer.dart';
class PopupLayer extends StatelessWidget {
final double width;
final double height;
final LatLng point;
final Alignment alignment;
final EdgeInsets padding;
final Key? childKey;
final Widget? child;
const PopupLayer({
super.key,
required this.width,
required this.height,
required this.point,
required this.alignment,
this.padding = EdgeInsets.zero,
this.childKey,
required this.child,
});
const PopupLayer.empty({Key? key})
: this(
key: key,
width: 0.0,
height: 0.0,
point: const LatLng(0.0, 0.0),
alignment: Alignment.topCenter,
padding: EdgeInsets.zero,
childKey: null,
child: null,
);
static final ScrollController _scrollController =
ScrollController(initialScrollOffset: 5000.0)
..addListener(() {
_scrollController.jumpTo(5000);
});
@override
Widget build(BuildContext context) {
return AnimatedSwitcher(
duration: const Duration(milliseconds: 250),
child: child == null
? null
: MarkerLayer(
key: childKey,
markers: [
Marker(
width: width + padding.horizontal,
height: height + padding.vertical,
point: point,
alignment: alignment,
child: Padding(
padding: padding,
child: GestureDetector(
onTap: () {},
child: Stack(children: [
// This hack prevents scroll events from reaching the map when there's no more content to scroll in the popup
SingleChildScrollView(
controller: _scrollController,
child: Container(height: 10000),
),
TransparentPointer(child: child),
]),
),
),
),
],
),
);
}
} |
Beta Was this translation helpful? Give feedback.
Strange. Let's try to use a MouseRegion with its onEnter and onExit callback. On enter, disable the scrollWheelZoom gesture of the map, on exit enable it again.