From ecde5e110952a7fa8433cb6fbb7899ab5ae2c11f Mon Sep 17 00:00:00 2001 From: ericz Date: Sat, 13 Jun 2026 20:01:43 +0200 Subject: [PATCH] fix StadiaMaps Dark and add demo. --- lib/models/app_settings.dart | 13 ++++++ lib/screens/app_settings_screen.dart | 22 ++++++---- lib/services/map_tile_cache_service.dart | 54 ++++++++++++++++++------ 3 files changed, 68 insertions(+), 21 deletions(-) diff --git a/lib/models/app_settings.dart b/lib/models/app_settings.dart index ed8a20a7..82b86248 100644 --- a/lib/models/app_settings.dart +++ b/lib/models/app_settings.dart @@ -76,6 +76,8 @@ class Cyr2LatProfile { class AppSettings { static const Object _unset = Object(); + static const String stadiaDemo = + '51bd0381-4685-4666-bae8-48940f6d77c0'; final bool clearPathOnMaxRetry; final bool mapShowRepeaters; @@ -125,6 +127,17 @@ class AppSettings { final List cyr2latProfiles; final String selectedCyr2latProfileId; + String get effectiveMapTileApiKey { + final apiKey = mapTileApiKey?.trim(); + if (apiKey == null || apiKey.isEmpty) { + return stadiaDemo; + } + return apiKey; + } + + bool get usesstadiaDemo => + effectiveMapTileApiKey == stadiaDemo; + Map get cyr2latCharMap { final profile = cyr2latProfiles.firstWhere( (p) => p.id == selectedCyr2latProfileId, diff --git a/lib/screens/app_settings_screen.dart b/lib/screens/app_settings_screen.dart index 10fa66cd..90a0a132 100644 --- a/lib/screens/app_settings_screen.dart +++ b/lib/screens/app_settings_screen.dart @@ -1019,11 +1019,9 @@ class AppSettingsScreen extends StatelessWidget { } String _mapApiKeySummary(BuildContext context, AppSettings settings) { - final apiKey = settings.mapTileApiKey?.trim(); - if (apiKey == null || apiKey.isEmpty) { - return context.l10n.appSettings_stadiaApiKeyRequired; - } - return context.l10n.appSettings_stadiaApiKeyConfigured(_maskApiKey(apiKey)); + return context.l10n.appSettings_stadiaApiKeyConfigured( + _maskApiKey(settings.effectiveMapTileApiKey), + ); } String _maskApiKey(String value) { @@ -1153,9 +1151,13 @@ class AppSettingsScreen extends StatelessWidget { BuildContext context, AppSettingsService settingsService, ) { - final controller = TextEditingController( - text: settingsService.settings.mapTileApiKey ?? '', + final currentApiKey = settingsService.settings.mapTileApiKey?.trim() ?? ''; + final maskedApiKey = _maskApiKey( + currentApiKey.isEmpty + ? AppSettings.stadiaDemo + : currentApiKey, ); + final controller = TextEditingController(text: maskedApiKey); showDialog( context: context, builder: (dialogContext) => AlertDialog( @@ -1173,6 +1175,7 @@ class AppSettingsScreen extends StatelessWidget { autofocus: true, autocorrect: false, enableSuggestions: false, + autofillHints: const [AutofillHints.password], decoration: const InputDecoration( border: OutlineInputBorder(), hintText: '4e1bf343-3d91-4d9c-a8e1-1234567890ab', @@ -1188,7 +1191,10 @@ class AppSettingsScreen extends StatelessWidget { ), TextButton( onPressed: () async { - await settingsService.setMapTileApiKey(controller.text); + final apiKey = controller.text.trim(); + await settingsService.setMapTileApiKey( + apiKey == maskedApiKey ? currentApiKey : apiKey, + ); if (!dialogContext.mounted) return; Navigator.pop(dialogContext); }, diff --git a/lib/services/map_tile_cache_service.dart b/lib/services/map_tile_cache_service.dart index df3c3fc7..07584132 100644 --- a/lib/services/map_tile_cache_service.dart +++ b/lib/services/map_tile_cache_service.dart @@ -305,8 +305,22 @@ class MapTileCacheService extends ChangeNotifier { appSettingsService.addListener(_handleSettingsChanged); } - MapRasterSourceDefinition get source => - MapRasterSourceCatalog.fromSettings(appSettingsService.settings); + MapRasterSourceDefinition get source { + final selectedSource = MapRasterSourceCatalog.fromSettings( + appSettingsService.settings, + ); + if (!selectedSource.allowsBulkDownload || + !appSettingsService.settings.usesstadiaDemo) { + return selectedSource; + } + return MapRasterSourceDefinition( + id: selectedSource.id, + label: selectedSource.label, + description: selectedSource.description, + isStadia: selectedSource.isStadia, + allowsBulkDownload: false, // Explicitly disable bulk download for demo. + ); + } MapRasterEndpointDefinition get endpoint => MapRasterEndpointCatalog.fromSettings(appSettingsService.settings); @@ -315,6 +329,26 @@ class MapTileCacheService extends ChangeNotifier { TileBuilder? get tileBuilder => null; + static bool shouldApplyDarkFilterForSettings( + AppSettings settings, + Brightness brightness, + ) { + switch (MapRasterSourcePreset.fromId(settings.mapRasterSourceId)) { + case MapRasterSourcePreset.osmDark: + case MapRasterSourcePreset.outdoorsDark: + case MapRasterSourcePreset.osmBrightDark: + return true; + case MapRasterSourcePreset.osmAuto: + return brightness == Brightness.dark; + case MapRasterSourcePreset.osmStandard: + case MapRasterSourcePreset.stamenTerrain: + case MapRasterSourcePreset.alidadeSmoothDark: + case MapRasterSourcePreset.outdoors: + case MapRasterSourcePreset.osmBright: + return false; + } + } + static const ColorFilter _darkMapFilter = ColorFilter.matrix([ -0.0850, -0.2861, @@ -345,7 +379,6 @@ class MapTileCacheService extends ChangeNotifier { }; Widget buildTileLayer(BuildContext context, {double opacity = 1}) { - final source = this.source; Widget layer = TileLayer( urlTemplate: urlTemplate, tileProvider: tileProvider, @@ -354,12 +387,10 @@ class MapTileCacheService extends ChangeNotifier { maxZoom: 19, ); - final shouldApplyDarkFilter = - source == MapRasterSourceCatalog.osmDark || - source == MapRasterSourceCatalog.outdoorsDark || - source == MapRasterSourceCatalog.osmBrightDark || - (source == MapRasterSourceCatalog.osmAuto && - Theme.of(context).brightness == Brightness.dark); + final shouldApplyDarkFilter = shouldApplyDarkFilterForSettings( + appSettingsService.settings, + Theme.of(context).brightness, + ); if (shouldApplyDarkFilter) { layer = ColorFiltered(colorFilter: _darkMapFilter, child: layer); @@ -608,12 +639,9 @@ class MapTileCacheService extends ChangeNotifier { return 'https://tile.openstreetmap.org/{z}/{x}/{y}.png'; } final endpoint = MapRasterEndpointCatalog.fromSettings(settings); - final apiKey = settings.mapTileApiKey?.trim(); + final apiKey = settings.effectiveMapTileApiKey; final base = 'https://${endpoint.host}/tiles/${source.id}/{z}/{x}/{y}${endpoint.scaleSuffix}.png'; - if (apiKey == null || apiKey.isEmpty) { - return base; - } final query = Uri(queryParameters: {'api_key': apiKey}).query; return '$base?$query'; }