Comments (10)
Hi @RafikRekhis, I'd be happy to help but I'll need some more context. If you can provide me with a minimal reproducible example (something I can run, as simplified as possible that still causes the exception) I can have a look.
from flutter_map_marker_popup.
We got the exact same problem I think.
We have some marker layer with a popup and some without. If I add two marker layers, one MarkerLayer
and one PopupMarkerLayer
, the problem is that the marker from the MarkerLayer
will always be above the popup from the marker in the PopupMarkerLayer
. In order to fix this we use two PopupMarkerLayer
and simply just don't display the popup if we don't need it. But when using more than one PopupMarkerLayer
we get the Multiple widgets used the same GlobalKey
Error.
from flutter_map_marker_popup.
@juliaen-dr can you provide a minimal reproducible example?
from flutter_map_marker_popup.
Sadly I can't share my code here but I tried to build an example. Basically just take a FlutterMap and add two MarkerLayer with popups. Now if you click on a Marker to open the popup you'll get the error.
FlutterMap(
mapController: _animatedMapController.mapController,
options: _mapOptions,
nonRotatedChildren: [],
children: [
MarkerClusterLayerWidget(
options: MarkerClusterLayerOptions(
maxClusterRadius: 50,
size: const Size(40, 40),
anchorPos: AnchorPos.align(AnchorAlign.center),
markers: _marker,
onMarkerTap: (marker) {
_onMarkerTap(marker);
},
popupOptions: PopupOptions(
popupBuilder: (BuildContext context, Marker marker) {
return buildMarkerPopup(marker, constraints.maxHeight);
},
popupController: _popupController,
buildPopupOnHover: false,
markerTapBehavior: MarkerTapBehavior.togglePopupAndHideRest(),
popupAnimation: const PopupAnimation.fade(),
)
),
builder: (context, markers) {
return Container();
},
),
),
MarkerClusterLayerWidget(
options: MarkerClusterLayerOptions(
maxClusterRadius: 50,
size: const Size(40, 40),
anchorPos: AnchorPos.align(AnchorAlign.center),
markers: _marker2,
onMarkerTap: (marker) {
_onMarkerTap(marker);
},
popupOptions: PopupOptions(
popupBuilder: (BuildContext context, Marker marker) {
return buildMarkerPopup(marker, constraints.maxHeight);
},
popupController: _popupController,
buildPopupOnHover: false,
markerTapBehavior: MarkerTapBehavior.togglePopupAndHideRest(),
popupAnimation: const PopupAnimation.fade(),
)
),
builder: (context, markers) {
return Container();
},
),
),
],
);
from flutter_map_marker_popup.
@juliaen-dr MarkerClusterLayerWidget
is from another package, you should open your issue in that repo. I no longer provide support for that package as I maintain my own marker clustering package with popup support.
from flutter_map_marker_popup.
If this issue persists when using flutter_map_marker_popup
alone I will be happy to look in to it if someone can provide me a minimal runnable reproduction of the error.
from flutter_map_marker_popup.
Hey!
I was able to reproduce this bug: For me this happens when multiple PopupMarkerLayers are sharing a single PopupController.
Minimal example:
import 'package:flutter_map/flutter_map.dart';
import 'package:flutter_map_marker_popup/flutter_map_marker_popup.dart';
import 'package:latlong2/latlong.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
MyApp({super.key});
final _controller = PopupController();
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
useMaterial3: true,
),
home: Scaffold(
body: FlutterMap(
options: const MapOptions(
initialZoom: 1,
),
children: [
TileLayer(
urlTemplate: 'https://tile.openstreetmap.org/{z}/{x}/{y}.png',
userAgentPackageName: 'flutter_map_marker_popup',
),
PopupMarkerLayer(options: _popupMarkerLayerFor(["qwe", "asd"])),
PopupMarkerLayer(options: _popupMarkerLayerFor(["hjk", "jkl"])),
],
),
),
);
}
PopupMarkerLayerOptions _popupMarkerLayerFor(List<String> list) {
return PopupMarkerLayerOptions(
markers: list.map((e) => Marker(point: LatLng(e.hashCode % 90, e.hashCode % 180), child: Text(e))).toList(),
markerTapBehavior: MarkerTapBehavior.togglePopupAndHideRest(),
markerCenterAnimation: const MarkerCenterAnimation(),
popupController: _controller,
popupDisplayOptions: PopupDisplayOptions(
builder: (context, Marker marker) {
return Card(
child: marker.child,
);
},
),
);
}
}
Thanks for the hard work! :)
from flutter_map_marker_popup.
Ah interesting, is there a use case for having them share a controller? I can't think of one right now. If there is none I will either document that this is not supported or see if I can add a warning when a shared controller is detected.
from flutter_map_marker_popup.
from flutter_map_marker_popup.
Hi All,
When there are multiple PopupMarkerLayer
, as long as PopupDisplayOptions
is not added, similar errors will not occur.
Minimal example:
import 'package:flutter/material.dart';
import 'package:flutter_map/flutter_map.dart';
import 'package:flutter_map_marker_popup/flutter_map_marker_popup.dart';
import 'package:latlong2/latlong.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
MyApp({super.key});
final PopupController _popupController = PopupController();
static final List<LatLng> _markersA = [
const LatLng(44.421, 10.404),
const LatLng(45.683, 10.839),
const LatLng(45.246, 5.783),
];
static final List<LatLng> _markersB = [
const LatLng(39.421, 10.404),
const LatLng(40.683, 10.839),
const LatLng(40.246, 5.783),
];
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
useMaterial3: true,
),
home: Scaffold(
body: PopupScope(
popupController: _popupController,
onPopupEvent: (event, selectedMarkers) {
debugPrint('$event: $selectedMarkers');
},
child: FlutterMap(
options: const MapOptions(
initialCenter: LatLng(42.5, 10.51),
initialZoom: 6.0,
),
children: [
TileLayer(
urlTemplate: 'https://tile.openstreetmap.org/{z}/{x}/{y}.png',
userAgentPackageName: 'flutter_map_marker_popup',
),
PopupMarkerLayer(options: _popupMarkerLayerFor(_markersA)),
PopupMarkerLayer(options: _popupMarkerLayerFor(_markersB)),
PopupLayer(
popupDisplayOptions: PopupDisplayOptions(
builder: (BuildContext context, Marker marker) {
return Card(
color: Colors.white,
child: Padding(
padding: const EdgeInsets.all(10),
child: GestureDetector(
onTap: () => debugPrint('Popup tap!'),
child: const Text(
'Container popup for marker',
),
),
),
);
}),
),
],
),
),
),
);
}
PopupMarkerLayerOptions _popupMarkerLayerFor(List<LatLng> list) {
return PopupMarkerLayerOptions(
markers: list.map((latLng) {
return Marker(point: latLng, child: const Icon(Icons.pin_drop));
}).toList(),
markerTapBehavior: MarkerTapBehavior.togglePopupAndHideRest(),
markerCenterAnimation: const MarkerCenterAnimation(),
popupController: _popupController,
/*
// Enabling this will throw an exception:
// Multiple widgets used the same GlobalKey.
popupDisplayOptions: PopupDisplayOptions(
builder: (context, Marker marker) {
return Card(
child: marker.child,
);
},
),
*/
);
}
}
from flutter_map_marker_popup.
Related Issues (20)
- Feature Request: Show popups inside current window HOT 4
- How to adjust popup snap for map rotation HOT 1
- PopupMarkerLayerOptions.popupBuilder callback is called multiple times when marker is clicked HOT 3
- How to show popup programmatically? HOT 2
- Can't use along flutter_map ^4.0.0 HOT 1
- marker popup not above other markers HOT 3
- Update latlong2 to 0.9.0 HOT 10
- Conflicts with plugin flutter_map_location_marker HOT 2
- method to check whether popup is showing or not HOT 6
- Popup doesn't appears HOT 1
- is the a version of this plugin for flutter_map 5 not 6?
- FM v6 is coming soon HOT 3
- Import conflict for LatLngTween with flutter_map 6.0.1 HOT 1
- How to get a popup to follow a marker when it moves? HOT 5
- How to create Draggable PopupMarker HOT 1
- The app was built, but the map is not working. HOT 1
- Question: how this can be adapted to work with mapbox_maps_flutter? HOT 1
- ERROR: The method 'subtract' isn't defined for the type 'Point'. HOT 1
- flutter_map 7 compatibility HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from flutter_map_marker_popup.