Skip to content

Commit

Permalink
fix: broken scalebar on web (#126)
Browse files Browse the repository at this point in the history
  • Loading branch information
josxha authored Nov 3, 2024
1 parent 95ff552 commit 3dfd257
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions lib/src/ui/map_scalebar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<double>(
future: futureMetersPerPixel,
builder: (context, snapshot) {
if (snapshot.data case final double data) {
return CustomPaint(painter: _ScaleBarPainter(data, theme));
}
return const SizedBox.shrink();
},
),
return FutureBuilder<double>(
future: futureMetersPerPixel,
builder: (context, snapshot) {
if (snapshot.data case final double data) {
return buildChild(data);
}
return const SizedBox.shrink();
},
);
}
}
Expand Down

0 comments on commit 3dfd257

Please sign in to comment.