This repository has been 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
93 lines (87 loc) · 3.09 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
import 'package:flutter/material.dart';
import 'package:flutter_map/flutter_map.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();
@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'],
),
],
nonRotatedLayers: <LayerOptions>[
// USAGE NOTE 3: Add the options for the plugin
LocationOptions(
locationButton(),
onLocationUpdate: (LatLngData? ld) {
print(
'Location updated: ${ld?.location} (accuracy: ${ld?.accuracy})');
},
onLocationRequested: (LatLngData? ld) {
if (ld == null) {
return;
}
mapController.move(ld.location, 16.0);
},
),
],
),
));
}
LocationButtonBuilder locationButton() {
return (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,
);
default:
return const Icon(
Icons.location_searching,
color: Colors.white,
);
}
}),
onPressed: () => onPressed()),
),
);
};
}
}