-
Notifications
You must be signed in to change notification settings - Fork 0
/
map_properties_route.dart
137 lines (124 loc) · 4.22 KB
/
map_properties_route.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
import 'package:design_system_flutter/design_system_flutter.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:sbb_maps_example/env.dart';
import 'package:sbb_maps_example/theme_provider.dart';
import 'package:sbb_maps_flutter/sbb_maps_flutter.dart';
class MapPropertiesRoute extends StatefulWidget {
const MapPropertiesRoute({super.key});
@override
State<MapPropertiesRoute> createState() => _MapPropertiesRouteState();
}
class _MapPropertiesRouteState extends State<MapPropertiesRoute> {
SBBMapProperties properties = const SBBMapProperties();
@override
Widget build(BuildContext context) {
final mapStyler = SBBRokasMapStyler.full(
apiKey: Env.journeyMapsTilesApiKey,
isDarkMode: Provider.of<ThemeProvider>(context).isDark,
);
return Scaffold(
appBar: const SBBHeader(title: 'Map Properties'),
body: SBBMap(
mapStyler: mapStyler,
isMyLocationEnabled: false,
isFloorSwitchingEnabled: true,
properties: properties,
builder: (context) => Align(
alignment: Alignment.topRight,
child: Padding(
padding: const EdgeInsets.all(sbbDefaultSpacing),
child: SBBMapIconButton(
onPressed: () {
showSBBModalSheet<SBBMapProperties>(
context: context,
title: 'Map Properties',
child: _MapPropertiesModalBody(properties: properties),
).then(_setStateWithProperties);
},
icon: SBBIcons.gears_small,
),
),
),
),
);
}
void _setStateWithProperties(SBBMapProperties? properties) {
setState(
() {
if (properties != null) {
this.properties = properties;
}
},
);
}
}
class _MapPropertiesModalBody extends StatefulWidget {
const _MapPropertiesModalBody({required this.properties});
final SBBMapProperties properties;
@override
State<_MapPropertiesModalBody> createState() => _MapPropertiesModalBodyState();
}
class _MapPropertiesModalBodyState extends State<_MapPropertiesModalBody> {
late SBBMapProperties _properties;
@override
void initState() {
_properties = widget.properties;
super.initState();
}
@override
Widget build(BuildContext context) {
return Padding(
padding: const EdgeInsets.symmetric(
vertical: sbbDefaultSpacing,
horizontal: sbbDefaultSpacing,
),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
SBBCheckboxListItem(
value: _properties.compassEnabled,
label: 'Enable Compass',
secondaryLabel: 'Show compass when map is rotated.',
onChanged: (v) => _setModalStateWithProperties(
_properties.copyWith(compassEnabled: v),
),
),
SBBCheckboxListItem(
value: _properties.zoomGesturesEnabled,
label: 'Enable Zoom',
secondaryLabel: 'Enable zoom gestures.',
onChanged: (v) => _setModalStateWithProperties(
_properties.copyWith(zoomGesturesEnabled: v),
),
),
SBBCheckboxListItem(
value: _properties.rotateGesturesEnabled,
label: 'Enable Rotation',
secondaryLabel: 'Enable rotation gesture.',
onChanged: (v) => _setModalStateWithProperties(
_properties.copyWith(rotateGesturesEnabled: v),
),
),
SBBCheckboxListItem(
value: _properties.scrollGesturesEnabled,
label: 'Enable Scroll',
secondaryLabel: 'Enable scrolling the map by pan gesture.',
onChanged: (v) => _setModalStateWithProperties(
_properties.copyWith(scrollGesturesEnabled: v),
),
isLastElement: true,
),
const SizedBox(height: sbbDefaultSpacing),
SBBPrimaryButton(label: 'Apply Changes', onPressed: () => Navigator.pop(context, _properties)),
const SizedBox(height: sbbDefaultSpacing),
],
),
);
}
void _setModalStateWithProperties(SBBMapProperties properties) {
setState(() {
_properties = properties;
});
}
}