diff --git a/lib/dev_config.dart b/lib/dev_config.dart index 5084fd7..18adfd8 100644 --- a/lib/dev_config.dart +++ b/lib/dev_config.dart @@ -3,8 +3,8 @@ import 'package:flutter/material.dart'; /// Developer/build-time configuration for global/non-user-tunable constants. -// Example: Default tile storage estimate (KB per tile), for size estimates -const double kTileEstimateKb = 25.0; +// Fallback tile storage estimate (KB per tile), used when no preview tile data is available +const double kFallbackTileEstimateKb = 25.0; // Direction cone for map view const double kDirectionConeHalfAngle = 30.0; // degrees diff --git a/lib/widgets/download_area_dialog.dart b/lib/widgets/download_area_dialog.dart index 59e6b6c..1242483 100644 --- a/lib/widgets/download_area_dialog.dart +++ b/lib/widgets/download_area_dialog.dart @@ -62,7 +62,8 @@ class _DownloadAreaDialogState extends State { final maxPossibleZoom = _calculateMaxZoomForTileLimit(bounds, minZoom); final nTiles = computeTileList(bounds, minZoom, maxZoom).length; - final totalMb = (nTiles * kTileEstimateKb) / 1024.0; + final tileEstimateKb = _getTileEstimateKb(); + final totalMb = (nTiles * tileEstimateKb) / 1024.0; final roundedMb = (totalMb * 10).round() / 10; // Round to nearest tenth setState(() { @@ -84,8 +85,22 @@ class _DownloadAreaDialogState extends State { } return kAbsoluteMaxZoom; } - + /// Get tile size estimate in KB, using preview tile data if available, otherwise fallback to constant + double _getTileEstimateKb() { + final appState = context.read(); + final selectedTileType = appState.selectedTileType; + + if (selectedTileType?.previewTile != null) { + // Use actual preview tile size + final previewSizeBytes = selectedTileType!.previewTile!.length; + final previewSizeKb = previewSizeBytes / 1024.0; + return previewSizeKb; + } else { + // Fall back to configured estimate + return kFallbackTileEstimateKb; + } + } @override Widget build(BuildContext context) {