-
-
Notifications
You must be signed in to change notification settings - Fork 36
/
main.dart
115 lines (109 loc) · 3.32 KB
/
main.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
import 'package:flutter/material.dart';
import 'package:flutter_map/flutter_map.dart';
import 'package:flutter_map_dragmarker/flutter_map_dragmarker.dart';
import 'package:latlong2/latlong.dart';
void main() => runApp(const TestApp());
class TestApp extends StatefulWidget {
const TestApp({super.key});
@override
TestAppState createState() => TestAppState();
}
class TestAppState extends State<TestApp> {
late final List<DragMarker> _dragMarkers;
@override
void initState() {
_dragMarkers = [
// minimal marker example
DragMarker(
key: GlobalKey<DragMarkerWidgetState>(),
point: const LatLng(45.535, -122.675),
size: const Size.square(50),
offset: const Offset(0, -20),
builder: (_, __, ___) => const Icon(
Icons.location_on,
size: 50,
color: Colors.blueGrey,
),
),
// marker with drag feedback, map scrolls when near edge
DragMarker(
key: GlobalKey<DragMarkerWidgetState>(),
point: const LatLng(45.2131, -122.6765),
size: const Size.square(75),
offset: const Offset(0, -20),
dragOffset: const Offset(0, -35),
builder: (_, __, isDragging) {
if (isDragging) {
return const Icon(
Icons.edit_location,
size: 75,
color: Colors.blueGrey,
);
}
return const Icon(
Icons.location_on,
size: 50,
color: Colors.blueGrey,
);
},
onDragStart: (details, point) => debugPrint("Start point $point"),
onDragEnd: (details, point) => debugPrint("End point $point"),
onTap: (point) => debugPrint("on tap"),
onLongPress: (point) => debugPrint("on long press"),
scrollMapNearEdge: true,
scrollNearEdgeRatio: 2.0,
scrollNearEdgeSpeed: 2.0,
),
// marker with position information
DragMarker(
key: GlobalKey<DragMarkerWidgetState>(),
point: const LatLng(45.4131, -122.9765),
size: const Size(75, 50),
builder: (_, pos, ___) {
return Card(
color: Colors.blueGrey,
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
pos.latitude.toStringAsFixed(3),
style: const TextStyle(color: Colors.white),
),
Text(
pos.longitude.toStringAsFixed(3),
style: const TextStyle(color: Colors.white),
),
],
),
);
},
),
];
super.initState();
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
body: Center(
child: FlutterMap(
options: const MapOptions(
initialCenter: LatLng(45.5231, -122.6765),
initialZoom: 9,
),
children: [
TileLayer(
urlTemplate: 'https://tile.openstreetmap.org/{z}/{x}/{y}.png',
),
DragMarkers(
markers: _dragMarkers,
alignment: Alignment.topCenter,
),
],
),
),
),
);
}
}