-
Notifications
You must be signed in to change notification settings - Fork 97
/
Copy pathmap_click.dart
79 lines (65 loc) · 1.96 KB
/
map_click.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
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:apple_maps_flutter/apple_maps_flutter.dart';
import 'package:flutter/material.dart';
import 'page.dart';
const CameraPosition _kInitialPosition = CameraPosition(
target: LatLng(-33.852, 151.211),
zoom: 11,
);
class MapClickPage extends ExamplePage {
MapClickPage() : super(const Icon(Icons.mouse), 'Map click');
@override
Widget build(BuildContext context) {
return SafeArea(child: const _MapClickBody());
}
}
class _MapClickBody extends StatefulWidget {
const _MapClickBody();
@override
State<StatefulWidget> createState() => _MapClickBodyState();
}
class _MapClickBodyState extends State<_MapClickBody> {
AppleMapController? mapController;
LatLng? _lastTap;
LatLng? _lastLongPress;
_MapClickBodyState();
@override
Widget build(BuildContext context) {
final AppleMap appleMap = AppleMap(
onMapCreated: onMapCreated,
initialCameraPosition: _kInitialPosition,
onTap: (LatLng pos) {
setState(() {
_lastTap = pos;
});
},
onLongPress: (LatLng pos) {
setState(() {
_lastLongPress = pos;
});
},
);
final List<Widget> columnChildren = <Widget>[Expanded(child: appleMap)];
if (mapController != null) {
final String lastTap = 'Tap:\n${_lastTap ?? ""}\n';
final String lastLongPress = 'Long press:\n${_lastLongPress ?? ""}';
columnChildren.add(Padding(
padding: EdgeInsets.all(8),
child: Column(
children: [
Text(lastTap, textAlign: TextAlign.center),
Text(lastLongPress, textAlign: TextAlign.center)
],
),
));
}
return Column(children: columnChildren);
}
void onMapCreated(AppleMapController controller) async {
setState(() {
mapController = controller;
});
}
}