From 3dfd257602329be8407cb038445fae33e7c7dde5 Mon Sep 17 00:00:00 2001 From: Joscha <34318751+josxha@users.noreply.github.com> Date: Sun, 3 Nov 2024 20:34:49 +0100 Subject: [PATCH] fix: broken scalebar on web (#126) --- lib/src/ui/map_scalebar.dart | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/lib/src/ui/map_scalebar.dart b/lib/src/ui/map_scalebar.dart index 90300761..b37d8c0e 100644 --- a/lib/src/ui/map_scalebar.dart +++ b/lib/src/ui/map_scalebar.dart @@ -21,26 +21,28 @@ class MapScalebar extends StatelessWidget { final latitude = camera.center.lat.toDouble(); final theme = Theme.of(context); + Widget buildChild(double metersPerPixel) => Container( + alignment: Alignment.bottomLeft, + padding: const EdgeInsets.all(12), + child: CustomPaint(painter: _ScaleBarPainter(metersPerPixel, theme)), + ); + if (kIsWeb) { final metersPerPixel = controller.getMetersPerPixelAtLatitudeSync(latitude); - return CustomPaint(painter: _ScaleBarPainter(metersPerPixel, theme)); + return buildChild(metersPerPixel); } final futureMetersPerPixel = controller.getMetersPerPixelAtLatitude(latitude); - return Container( - alignment: Alignment.bottomLeft, - padding: const EdgeInsets.all(12), - child: FutureBuilder( - future: futureMetersPerPixel, - builder: (context, snapshot) { - if (snapshot.data case final double data) { - return CustomPaint(painter: _ScaleBarPainter(data, theme)); - } - return const SizedBox.shrink(); - }, - ), + return FutureBuilder( + future: futureMetersPerPixel, + builder: (context, snapshot) { + if (snapshot.data case final double data) { + return buildChild(data); + } + return const SizedBox.shrink(); + }, ); } }