-
-
Notifications
You must be signed in to change notification settings - Fork 860
/
zoombuttons_plugin.dart
78 lines (73 loc) · 2.24 KB
/
zoombuttons_plugin.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
import 'dart:math';
import 'package:flutter/material.dart';
import 'package:flutter_map/flutter_map.dart';
class FlutterMapZoomButtons extends StatelessWidget {
final double minZoom;
final double maxZoom;
final bool mini;
final double padding;
final Alignment alignment;
final Color? zoomInColor;
final Color? zoomInColorIcon;
final Color? zoomOutColor;
final Color? zoomOutColorIcon;
final IconData zoomInIcon;
final IconData zoomOutIcon;
const FlutterMapZoomButtons({
super.key,
this.minZoom = 1,
this.maxZoom = 18,
this.mini = true,
this.padding = 2.0,
this.alignment = Alignment.topRight,
this.zoomInColor,
this.zoomInColorIcon,
this.zoomInIcon = Icons.zoom_in,
this.zoomOutColor,
this.zoomOutColorIcon,
this.zoomOutIcon = Icons.zoom_out,
});
@override
Widget build(BuildContext context) {
final controller = MapController.of(context);
final camera = MapCamera.of(context);
final theme = Theme.of(context);
return Align(
alignment: alignment,
child: Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Padding(
padding:
EdgeInsets.only(left: padding, top: padding, right: padding),
child: FloatingActionButton(
heroTag: 'zoomInButton',
mini: mini,
backgroundColor: zoomInColor ?? theme.primaryColor,
onPressed: () {
final zoom = min(camera.zoom + 1, maxZoom);
controller.move(camera.center, zoom);
},
child: Icon(zoomInIcon,
color: zoomInColorIcon ?? theme.iconTheme.color),
),
),
Padding(
padding: EdgeInsets.all(padding),
child: FloatingActionButton(
heroTag: 'zoomOutButton',
mini: mini,
backgroundColor: zoomOutColor ?? theme.primaryColor,
onPressed: () {
final zoom = max(camera.zoom - 1, minZoom);
controller.move(camera.center, zoom);
},
child: Icon(zoomOutIcon,
color: zoomOutColorIcon ?? theme.iconTheme.color),
),
),
],
),
);
}
}