-
Notifications
You must be signed in to change notification settings - Fork 274
/
map_page.dart
104 lines (95 loc) · 3 KB
/
map_page.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
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_devfest/config/config_bloc.dart';
import 'package:flutter_devfest/universal/dev_scaffold.dart';
import 'package:google_maps_flutter/google_maps_flutter.dart';
class MapPage extends StatefulWidget {
static const String routeName = "/map";
@override
_MapPageState createState() => _MapPageState();
}
class _MapPageState extends State<MapPage> {
GoogleMapController _controller;
bool isMapCreated = false;
static final LatLng myLocation = LatLng(37.42796133580664, -122.085749655962);
@override
void initState() {
super.initState();
}
final CameraPosition _kGooglePlex = CameraPosition(
target: myLocation,
zoom: 14.4746,
);
Set<Marker> _createMarker() {
return <Marker>[
Marker(
markerId: MarkerId("marker_1"),
position: myLocation,
icon: BitmapDescriptor.defaultMarkerWithHue(
BitmapDescriptor.hueOrange,
)),
].toSet();
}
changeMapMode() {
if (ConfigBloc().darkModeOn) {
getJsonFile("assets/nightmode.json").then(setMapStyle);
} else {
getJsonFile("assets/daymode.json").then(setMapStyle);
}
}
Future<String> getJsonFile(String path) async {
return await rootBundle.loadString(path);
}
void setMapStyle(String mapStyle) {
_controller.setMapStyle(mapStyle);
}
@override
Widget build(BuildContext context) {
if (isMapCreated) {
changeMapMode();
}
return DevScaffold(
body: Padding(
padding: const EdgeInsets.only(top: 1.0),
child: Stack(
fit: StackFit.expand,
children: <Widget>[
GoogleMap(
mapType: MapType.normal,
zoomGesturesEnabled: true,
myLocationButtonEnabled: true,
myLocationEnabled: true,
markers: _createMarker(),
initialCameraPosition: _kGooglePlex,
onMapCreated: (GoogleMapController controller) {
_controller = controller;
isMapCreated = true;
changeMapMode();
setState(() {});
},
),
IgnorePointer(
child: Padding(
padding: const EdgeInsets.all(8.0),
child: RichText(
textAlign: TextAlign.center,
text: TextSpan(
text: "Google Office\n",
style: Theme.of(context).textTheme.title.copyWith(
fontWeight: FontWeight.bold,
),
children: [
TextSpan(
text: "Shoreline Amphitheatre, Mountain View, CA",
style: Theme.of(context).textTheme.subtitle,
children: []),
]),
)),
)
],
),
),
title: "Locate Us",
);
}
}