@@ -17,6 +17,7 @@ class MapWidget extends ConsumerStatefulWidget {
17
17
double ? aspectRatio,
18
18
bool aspectRatioNeeded = true ,
19
19
bool roundedCorners = true ,
20
+ Widget ? mapLegend,
20
21
}) {
21
22
return MapWidget ._(
22
23
markers: markers,
@@ -26,6 +27,7 @@ class MapWidget extends ConsumerStatefulWidget {
26
27
aspectRatio: aspectRatio,
27
28
aspectRatioNeeded: aspectRatioNeeded,
28
29
roundedCorners: roundedCorners,
30
+ mapLegend: mapLegend,
29
31
);
30
32
}
31
33
@@ -37,6 +39,7 @@ class MapWidget extends ConsumerStatefulWidget {
37
39
double ? aspectRatio,
38
40
bool aspectRatioNeeded = true ,
39
41
bool roundedCorners = true ,
42
+ Widget ? mapLegend,
40
43
}) {
41
44
return MapWidget ._(
42
45
markers: markers,
@@ -47,6 +50,7 @@ class MapWidget extends ConsumerStatefulWidget {
47
50
controlPadding: controlPadding,
48
51
aspectRatioNeeded: aspectRatioNeeded,
49
52
roundedCorners: roundedCorners,
53
+ mapLegend: mapLegend,
50
54
);
51
55
}
52
56
@@ -59,6 +63,7 @@ class MapWidget extends ConsumerStatefulWidget {
59
63
double ? aspectRatio,
60
64
bool aspectRatioNeeded = true ,
61
65
bool roundedCorners = true ,
66
+ Widget ? mapLegend,
62
67
}) {
63
68
return MapWidget ._(
64
69
markers: markers,
@@ -69,6 +74,7 @@ class MapWidget extends ConsumerStatefulWidget {
69
74
aspectRatio: aspectRatio,
70
75
aspectRatioNeeded: aspectRatioNeeded,
71
76
roundedCorners: roundedCorners,
77
+ mapLegend: mapLegend,
72
78
);
73
79
}
74
80
@@ -81,6 +87,7 @@ class MapWidget extends ConsumerStatefulWidget {
81
87
this .controlPadding,
82
88
required this .aspectRatioNeeded,
83
89
required this .roundedCorners,
90
+ this .mapLegend,
84
91
});
85
92
86
93
final Set <Marker > markers;
@@ -91,6 +98,7 @@ class MapWidget extends ConsumerStatefulWidget {
91
98
final bool roundedCorners;
92
99
final EdgeInsets ? padding;
93
100
final EdgeInsets ? controlPadding;
101
+ final Widget ? mapLegend;
94
102
95
103
@override
96
104
ConsumerState <ConsumerStatefulWidget > createState () => _MapWidgetState ();
@@ -134,40 +142,52 @@ class _MapWidgetState extends ConsumerState<MapWidget> {
134
142
curve: Curves .fastOutSlowIn,
135
143
opacity: isMapVisible ? 1.0 : 0.01 ,
136
144
duration: const Duration (milliseconds: 200 ),
137
- child: GoogleMap (
138
- style:
139
- Theme .of (context).brightness == Brightness .light
140
- ? getIt.get <MapThemeService >().lightTheme
141
- : getIt.get <MapThemeService >().darkTheme,
142
- mapType: MapType .normal,
143
- padding: widget.controlPadding ?? EdgeInsets .zero,
144
- initialCameraPosition: CameraPosition (
145
- target:
146
- widget.latLng ??
147
- const LatLng (48.26307794976663 , 11.668018668778569 ),
148
- zoom: widget.zoom ?? 10 ,
149
- ),
150
- gestureRecognizers: {
151
- Factory <OneSequenceGestureRecognizer >(() => EagerGestureRecognizer ()),
152
- },
153
- rotateGesturesEnabled: false ,
154
- compassEnabled: false ,
155
- mapToolbarEnabled: false ,
156
- tiltGesturesEnabled: false ,
157
- zoomControlsEnabled: true ,
158
- myLocationEnabled: true ,
159
- myLocationButtonEnabled: true ,
160
- markers: widget.markers,
161
- onMapCreated: (GoogleMapController controller) {
162
- _controller.complete (controller);
163
- Future .delayed (const Duration (milliseconds: 250 ), () {
164
- if (mounted) {
165
- setState (() {
166
- isMapVisible = true ;
145
+ child: Stack (
146
+ alignment: Alignment .topRight,
147
+ children: [
148
+ GoogleMap (
149
+ style:
150
+ Theme .of (context).brightness == Brightness .light
151
+ ? getIt.get <MapThemeService >().lightTheme
152
+ : getIt.get <MapThemeService >().darkTheme,
153
+ mapType: MapType .normal,
154
+ padding: widget.controlPadding ?? EdgeInsets .zero,
155
+ initialCameraPosition: CameraPosition (
156
+ target:
157
+ widget.latLng ??
158
+ const LatLng (48.26307794976663 , 11.668018668778569 ),
159
+ zoom: widget.zoom ?? 10 ,
160
+ ),
161
+ gestureRecognizers: {
162
+ Factory <OneSequenceGestureRecognizer >(
163
+ () => EagerGestureRecognizer (),
164
+ ),
165
+ },
166
+ rotateGesturesEnabled: false ,
167
+ compassEnabled: false ,
168
+ mapToolbarEnabled: false ,
169
+ tiltGesturesEnabled: false ,
170
+ zoomControlsEnabled: true ,
171
+ myLocationEnabled: true ,
172
+ myLocationButtonEnabled: true ,
173
+ markers: widget.markers,
174
+ onMapCreated: (GoogleMapController controller) {
175
+ _controller.complete (controller);
176
+ Future .delayed (const Duration (milliseconds: 250 ), () {
177
+ if (mounted) {
178
+ setState (() {
179
+ isMapVisible = true ;
180
+ });
181
+ }
167
182
});
168
- }
169
- });
170
- },
183
+ },
184
+ ),
185
+ if (widget.mapLegend != null )
186
+ Padding (
187
+ padding: EdgeInsets .all (context.padding),
188
+ child: widget.mapLegend! ,
189
+ ),
190
+ ],
171
191
),
172
192
);
173
193
}
0 commit comments