Skip to content

Commit cf5f42c

Browse files
committed
Enhance Campus Map Legend
1 parent cdfdd4f commit cf5f42c

File tree

4 files changed

+112
-91
lines changed

4 files changed

+112
-91
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import 'package:campus_flutter/base/extensions/context.dart';
2+
import 'package:campus_flutter/base/util/icon_text.dart' show IconText;
3+
import 'package:easy_localization/easy_localization.dart';
4+
import 'package:flutter/material.dart';
5+
6+
class CampusMapLegend extends StatelessWidget {
7+
const CampusMapLegend({super.key});
8+
9+
@override
10+
Widget build(BuildContext context) {
11+
return Container(
12+
decoration: BoxDecoration(
13+
color: context.theme.canvasColor,
14+
borderRadius: BorderRadius.circular(15),
15+
boxShadow: [
16+
if (context.theme.brightness == Brightness.light)
17+
BoxShadow(
18+
color: Colors.grey,
19+
blurRadius: 1.0,
20+
offset: Offset(0, 2),
21+
),
22+
],
23+
),
24+
child: Padding(
25+
padding: EdgeInsets.all(context.padding),
26+
child: Column(
27+
crossAxisAlignment: CrossAxisAlignment.start,
28+
mainAxisSize: MainAxisSize.min,
29+
children: [
30+
IconText(
31+
iconData: Icons.place,
32+
label: context.tr("cafeterias"),
33+
iconColor: Colors.blue,
34+
),
35+
Padding(
36+
padding: EdgeInsets.symmetric(vertical: context.halfPadding),
37+
),
38+
IconText(
39+
iconData: Icons.place,
40+
label: context.tr("studyRooms"),
41+
iconColor: Colors.red,
42+
),
43+
],
44+
),
45+
),
46+
);
47+
}
48+
}
Lines changed: 9 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
import 'package:campus_flutter/base/enums/campus.dart';
2-
import 'package:campus_flutter/base/extensions/context.dart';
32
import 'package:campus_flutter/base/util/custom_back_button.dart';
4-
import 'package:campus_flutter/base/util/icon_text.dart';
53
import 'package:campus_flutter/placesComponent/viewModels/places_viewmodel.dart';
4+
import 'package:campus_flutter/placesComponent/views/campuses/campus_map_legend.dart';
65
import 'package:campus_flutter/placesComponent/views/map_widget.dart';
7-
import 'package:easy_localization/easy_localization.dart';
86
import 'package:flutter/material.dart';
97
import 'package:flutter_riverpod/flutter_riverpod.dart';
108
import 'package:google_maps_flutter/google_maps_flutter.dart';
@@ -34,61 +32,14 @@ class CampusMapView extends ConsumerWidget {
3432

3533
@override
3634
Widget build(BuildContext context, WidgetRef ref) {
37-
return Stack(
38-
alignment: Alignment.topRight,
39-
children: [
40-
MapWidget.noPadding(
41-
aspectRatioNeeded: false,
42-
markers: ref.read(placesViewModel).getCampusMarkers(context, campus),
43-
latLng: LatLng(campus.location.latitude, campus.location.longitude),
44-
zoom: 15,
45-
roundedCorners: false,
46-
controlPadding: const EdgeInsets.all(20),
47-
),
48-
_mapLegend(context),
49-
],
50-
);
51-
}
52-
53-
Widget _mapLegend(BuildContext context) {
54-
return Padding(
55-
padding: EdgeInsets.all(context.padding),
56-
child: Container(
57-
decoration: BoxDecoration(
58-
color: context.theme.canvasColor,
59-
borderRadius: BorderRadius.circular(15),
60-
boxShadow: [
61-
if (context.theme.brightness == Brightness.light)
62-
BoxShadow(
63-
color: Colors.grey,
64-
blurRadius: 1.0,
65-
offset: Offset(0, 2),
66-
),
67-
],
68-
),
69-
child: Padding(
70-
padding: EdgeInsets.all(context.padding),
71-
child: Column(
72-
crossAxisAlignment: CrossAxisAlignment.start,
73-
mainAxisSize: MainAxisSize.min,
74-
children: [
75-
IconText(
76-
iconData: Icons.place,
77-
label: context.tr("cafeterias"),
78-
iconColor: Colors.blue,
79-
),
80-
Padding(
81-
padding: EdgeInsets.symmetric(vertical: context.halfPadding),
82-
),
83-
IconText(
84-
iconData: Icons.place,
85-
label: context.tr("studyRooms"),
86-
iconColor: Colors.red,
87-
),
88-
],
89-
),
90-
),
91-
),
35+
return MapWidget.noPadding(
36+
aspectRatioNeeded: false,
37+
markers: ref.read(placesViewModel).getCampusMarkers(context, campus),
38+
latLng: LatLng(campus.location.latitude, campus.location.longitude),
39+
zoom: 15,
40+
roundedCorners: false,
41+
controlPadding: const EdgeInsets.all(20),
42+
mapLegend: CampusMapLegend(),
9243
);
9344
}
9445
}

lib/placesComponent/views/campuses/campus_view.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import 'package:campus_flutter/placesComponent/viewModels/cafeterias_viewmodel.d
99
import 'package:campus_flutter/placesComponent/viewModels/places_viewmodel.dart';
1010
import 'package:campus_flutter/placesComponent/viewModels/study_rooms_viewmodel.dart';
1111
import 'package:campus_flutter/placesComponent/views/cafeterias/cafeteria_row_view.dart';
12+
import 'package:campus_flutter/placesComponent/views/campuses/campus_map_legend.dart';
1213
import 'package:campus_flutter/placesComponent/views/campuses/campus_most_searched_view.dart';
1314
import 'package:campus_flutter/placesComponent/views/homeWidget/study_room_widget_view.dart';
1415
import 'package:campus_flutter/placesComponent/views/map_widget.dart';
@@ -92,6 +93,7 @@ class _CampusViewState extends ConsumerState<CampusView> {
9293
widget.campus.location.longitude,
9394
),
9495
zoom: 15,
96+
mapLegend: CampusMapLegend(),
9597
),
9698
),
9799
),

lib/placesComponent/views/map_widget.dart

Lines changed: 53 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ class MapWidget extends ConsumerStatefulWidget {
1717
double? aspectRatio,
1818
bool aspectRatioNeeded = true,
1919
bool roundedCorners = true,
20+
Widget? mapLegend,
2021
}) {
2122
return MapWidget._(
2223
markers: markers,
@@ -26,6 +27,7 @@ class MapWidget extends ConsumerStatefulWidget {
2627
aspectRatio: aspectRatio,
2728
aspectRatioNeeded: aspectRatioNeeded,
2829
roundedCorners: roundedCorners,
30+
mapLegend: mapLegend,
2931
);
3032
}
3133

@@ -37,6 +39,7 @@ class MapWidget extends ConsumerStatefulWidget {
3739
double? aspectRatio,
3840
bool aspectRatioNeeded = true,
3941
bool roundedCorners = true,
42+
Widget? mapLegend,
4043
}) {
4144
return MapWidget._(
4245
markers: markers,
@@ -47,6 +50,7 @@ class MapWidget extends ConsumerStatefulWidget {
4750
controlPadding: controlPadding,
4851
aspectRatioNeeded: aspectRatioNeeded,
4952
roundedCorners: roundedCorners,
53+
mapLegend: mapLegend,
5054
);
5155
}
5256

@@ -59,6 +63,7 @@ class MapWidget extends ConsumerStatefulWidget {
5963
double? aspectRatio,
6064
bool aspectRatioNeeded = true,
6165
bool roundedCorners = true,
66+
Widget? mapLegend,
6267
}) {
6368
return MapWidget._(
6469
markers: markers,
@@ -69,6 +74,7 @@ class MapWidget extends ConsumerStatefulWidget {
6974
aspectRatio: aspectRatio,
7075
aspectRatioNeeded: aspectRatioNeeded,
7176
roundedCorners: roundedCorners,
77+
mapLegend: mapLegend,
7278
);
7379
}
7480

@@ -81,6 +87,7 @@ class MapWidget extends ConsumerStatefulWidget {
8187
this.controlPadding,
8288
required this.aspectRatioNeeded,
8389
required this.roundedCorners,
90+
this.mapLegend,
8491
});
8592

8693
final Set<Marker> markers;
@@ -91,6 +98,7 @@ class MapWidget extends ConsumerStatefulWidget {
9198
final bool roundedCorners;
9299
final EdgeInsets? padding;
93100
final EdgeInsets? controlPadding;
101+
final Widget? mapLegend;
94102

95103
@override
96104
ConsumerState<ConsumerStatefulWidget> createState() => _MapWidgetState();
@@ -134,40 +142,52 @@ class _MapWidgetState extends ConsumerState<MapWidget> {
134142
curve: Curves.fastOutSlowIn,
135143
opacity: isMapVisible ? 1.0 : 0.01,
136144
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+
}
167182
});
168-
}
169-
});
170-
},
183+
},
184+
),
185+
if (widget.mapLegend != null)
186+
Padding(
187+
padding: EdgeInsets.all(context.padding),
188+
child: widget.mapLegend!,
189+
),
190+
],
171191
),
172192
);
173193
}

0 commit comments

Comments
 (0)