From 2c69342e86885fc9eb466e256e03a98f7f209475 Mon Sep 17 00:00:00 2001 From: chriscant Date: Sun, 9 Jan 2022 20:31:24 +0000 Subject: [PATCH 1/2] Fix ZoomButtonsPluginOption to check min and max properly --- .../lib/pages/zoombuttons_plugin_option.dart | 45 +++++++------------ 1 file changed, 16 insertions(+), 29 deletions(-) diff --git a/example/lib/pages/zoombuttons_plugin_option.dart b/example/lib/pages/zoombuttons_plugin_option.dart index fa879d223..83f94ce2a 100644 --- a/example/lib/pages/zoombuttons_plugin_option.dart +++ b/example/lib/pages/zoombuttons_plugin_option.dart @@ -3,8 +3,8 @@ import 'package:flutter_map/flutter_map.dart'; import 'package:flutter_map/plugin_api.dart'; class ZoomButtonsPluginOption extends LayerOptions { - final int minZoom; - final int maxZoom; + final double minZoom; + final double maxZoom; final bool mini; final double padding; final Alignment alignment; @@ -34,8 +34,7 @@ class ZoomButtonsPluginOption extends LayerOptions { class ZoomButtonsPlugin implements MapPlugin { @override - Widget createLayer( - LayerOptions options, MapState mapState, Stream stream) { + Widget createLayer(LayerOptions options, MapState mapState, Stream stream) { if (options is ZoomButtonsPluginOption) { return ZoomButtons(options, mapState, stream); } @@ -52,11 +51,9 @@ class ZoomButtons extends StatelessWidget { final ZoomButtonsPluginOption zoomButtonsOpts; final MapState map; final Stream stream; - final FitBoundsOptions options = - const FitBoundsOptions(padding: EdgeInsets.all(12.0)); + final FitBoundsOptions options = const FitBoundsOptions(padding: EdgeInsets.all(12.0)); - ZoomButtons(this.zoomButtonsOpts, this.map, this.stream) - : super(key: zoomButtonsOpts.key); + ZoomButtons(this.zoomButtonsOpts, this.map, this.stream) : super(key: zoomButtonsOpts.key); @override Widget build(BuildContext context) { @@ -67,28 +64,22 @@ class ZoomButtons extends StatelessWidget { children: [ Padding( padding: EdgeInsets.only( - left: zoomButtonsOpts.padding, - top: zoomButtonsOpts.padding, - right: zoomButtonsOpts.padding), + left: zoomButtonsOpts.padding, top: zoomButtonsOpts.padding, right: zoomButtonsOpts.padding), child: FloatingActionButton( heroTag: 'zoomInButton', mini: zoomButtonsOpts.mini, - backgroundColor: - zoomButtonsOpts.zoomInColor ?? Theme.of(context).primaryColor, + backgroundColor: zoomButtonsOpts.zoomInColor ?? Theme.of(context).primaryColor, onPressed: () { var bounds = map.getBounds(); var centerZoom = map.getBoundsCenterZoom(bounds, options); var zoom = centerZoom.zoom + 1; - if (zoom < zoomButtonsOpts.minZoom) { - zoom = zoomButtonsOpts.minZoom as double; - } else { - map.move(centerZoom.center, zoom, - source: MapEventSource.custom); + if (zoom > zoomButtonsOpts.maxZoom) { + zoom = zoomButtonsOpts.maxZoom; } + map.move(centerZoom.center, zoom, source: MapEventSource.custom); }, child: Icon(zoomButtonsOpts.zoomInIcon, - color: zoomButtonsOpts.zoomInColorIcon ?? - IconTheme.of(context).color), + color: zoomButtonsOpts.zoomInColorIcon ?? IconTheme.of(context).color), ), ), Padding( @@ -96,22 +87,18 @@ class ZoomButtons extends StatelessWidget { child: FloatingActionButton( heroTag: 'zoomOutButton', mini: zoomButtonsOpts.mini, - backgroundColor: zoomButtonsOpts.zoomOutColor ?? - Theme.of(context).primaryColor, + backgroundColor: zoomButtonsOpts.zoomOutColor ?? Theme.of(context).primaryColor, onPressed: () { var bounds = map.getBounds(); var centerZoom = map.getBoundsCenterZoom(bounds, options); var zoom = centerZoom.zoom - 1; - if (zoom > zoomButtonsOpts.maxZoom) { - zoom = zoomButtonsOpts.maxZoom as double; - } else { - map.move(centerZoom.center, zoom, - source: MapEventSource.custom); + if (zoom < zoomButtonsOpts.minZoom) { + zoom = zoomButtonsOpts.minZoom; } + map.move(centerZoom.center, zoom, source: MapEventSource.custom); }, child: Icon(zoomButtonsOpts.zoomOutIcon, - color: zoomButtonsOpts.zoomOutColorIcon ?? - IconTheme.of(context).color), + color: zoomButtonsOpts.zoomOutColorIcon ?? IconTheme.of(context).color), ), ), ], From 4a3c16034024a25151183f8f2b5375b84e66af05 Mon Sep 17 00:00:00 2001 From: chriscant Date: Sun, 9 Jan 2022 20:39:10 +0000 Subject: [PATCH 2/2] Fix ZoomButtonsPluginOption to check min and max properly --- .../lib/pages/zoombuttons_plugin_option.dart | 31 +++++++++++++------ 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/example/lib/pages/zoombuttons_plugin_option.dart b/example/lib/pages/zoombuttons_plugin_option.dart index 83f94ce2a..e29d5926f 100644 --- a/example/lib/pages/zoombuttons_plugin_option.dart +++ b/example/lib/pages/zoombuttons_plugin_option.dart @@ -34,7 +34,8 @@ class ZoomButtonsPluginOption extends LayerOptions { class ZoomButtonsPlugin implements MapPlugin { @override - Widget createLayer(LayerOptions options, MapState mapState, Stream stream) { + Widget createLayer( + LayerOptions options, MapState mapState, Stream stream) { if (options is ZoomButtonsPluginOption) { return ZoomButtons(options, mapState, stream); } @@ -51,9 +52,11 @@ class ZoomButtons extends StatelessWidget { final ZoomButtonsPluginOption zoomButtonsOpts; final MapState map; final Stream stream; - final FitBoundsOptions options = const FitBoundsOptions(padding: EdgeInsets.all(12.0)); + final FitBoundsOptions options = + const FitBoundsOptions(padding: EdgeInsets.all(12.0)); - ZoomButtons(this.zoomButtonsOpts, this.map, this.stream) : super(key: zoomButtonsOpts.key); + ZoomButtons(this.zoomButtonsOpts, this.map, this.stream) + : super(key: zoomButtonsOpts.key); @override Widget build(BuildContext context) { @@ -64,11 +67,14 @@ class ZoomButtons extends StatelessWidget { children: [ Padding( padding: EdgeInsets.only( - left: zoomButtonsOpts.padding, top: zoomButtonsOpts.padding, right: zoomButtonsOpts.padding), + left: zoomButtonsOpts.padding, + top: zoomButtonsOpts.padding, + right: zoomButtonsOpts.padding), child: FloatingActionButton( heroTag: 'zoomInButton', mini: zoomButtonsOpts.mini, - backgroundColor: zoomButtonsOpts.zoomInColor ?? Theme.of(context).primaryColor, + backgroundColor: + zoomButtonsOpts.zoomInColor ?? Theme.of(context).primaryColor, onPressed: () { var bounds = map.getBounds(); var centerZoom = map.getBoundsCenterZoom(bounds, options); @@ -76,10 +82,12 @@ class ZoomButtons extends StatelessWidget { if (zoom > zoomButtonsOpts.maxZoom) { zoom = zoomButtonsOpts.maxZoom; } - map.move(centerZoom.center, zoom, source: MapEventSource.custom); + map.move(centerZoom.center, zoom, + source: MapEventSource.custom); }, child: Icon(zoomButtonsOpts.zoomInIcon, - color: zoomButtonsOpts.zoomInColorIcon ?? IconTheme.of(context).color), + color: zoomButtonsOpts.zoomInColorIcon ?? + IconTheme.of(context).color), ), ), Padding( @@ -87,7 +95,8 @@ class ZoomButtons extends StatelessWidget { child: FloatingActionButton( heroTag: 'zoomOutButton', mini: zoomButtonsOpts.mini, - backgroundColor: zoomButtonsOpts.zoomOutColor ?? Theme.of(context).primaryColor, + backgroundColor: zoomButtonsOpts.zoomOutColor ?? + Theme.of(context).primaryColor, onPressed: () { var bounds = map.getBounds(); var centerZoom = map.getBoundsCenterZoom(bounds, options); @@ -95,10 +104,12 @@ class ZoomButtons extends StatelessWidget { if (zoom < zoomButtonsOpts.minZoom) { zoom = zoomButtonsOpts.minZoom; } - map.move(centerZoom.center, zoom, source: MapEventSource.custom); + map.move(centerZoom.center, zoom, + source: MapEventSource.custom); }, child: Icon(zoomButtonsOpts.zoomOutIcon, - color: zoomButtonsOpts.zoomOutColorIcon ?? IconTheme.of(context).color), + color: zoomButtonsOpts.zoomOutColorIcon ?? + IconTheme.of(context).color), ), ), ],