This repository was archived by the owner on Sep 19, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 35
/
Copy pathdefault.dart
94 lines (89 loc) · 3.59 KB
/
default.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
import 'package:flutter/material.dart';
import 'package:flutter_map/flutter_map.dart';
import 'package:latlong/latlong.dart';
import 'package:flutter_map_location/flutter_map_location.dart';
import '../widgets/drawer.dart';
class DefaultPage extends StatefulWidget {
static const String route = '/';
@override
_DefaultPageState createState() => _DefaultPageState();
}
class _DefaultPageState extends State<DefaultPage> {
// USAGE NOTE 1: Add a controler and marker list:
final MapController mapController = MapController();
final List<Marker> userLocationMarkers = <Marker>[];
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Default'),
),
drawer: buildDrawer(context, DefaultPage.route),
body: Center(
child: FlutterMap(
mapController: mapController,
options: MapOptions(
plugins: <MapPlugin>[
// USAGE NOTE 2: Add the plugin
LocationPlugin(),
],
),
layers: <LayerOptions>[
TileLayerOptions(
urlTemplate:
'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
subdomains: <String>['a', 'b', 'c'],
),
// USAGE NOTE 3: Add the layer for the marker
MarkerLayerOptions(markers: userLocationMarkers),
// USAGE NOTE 4: Add the options for the plugin
LocationOptions(
markers: userLocationMarkers,
onLocationUpdate: (LatLng loc) {
print('Location updated: $loc');
},
onLocationRequested: (LatLng loc) {
if (loc == null) {
return;
}
mapController?.move(loc, 16.0);
},
buttonBuilder: (BuildContext context,
ValueNotifier<LocationServiceStatus> status,
Function onPressed) {
return Align(
alignment: Alignment.bottomRight,
child: Padding(
padding: const EdgeInsets.only(bottom: 16.0, right: 16.0),
child: FloatingActionButton(
child: ValueListenableBuilder<LocationServiceStatus>(
valueListenable: status,
builder: (BuildContext context,
LocationServiceStatus value, Widget child) {
switch (value) {
case LocationServiceStatus.disabled:
case LocationServiceStatus.permissionDenied:
case LocationServiceStatus.unsubscribed:
return const Icon(
Icons.location_disabled,
color: Colors.white,
);
break;
default:
return const Icon(
Icons.location_searching,
color: Colors.white,
);
break;
}
}),
onPressed: () => onPressed()),
),
);
},
),
],
),
));
}
}