fix StadiaMaps Dark and add demo.

This commit is contained in:
ericz
2026-06-13 20:01:43 +02:00
parent f548f95e29
commit ecde5e1109
3 changed files with 68 additions and 21 deletions
+13
View File
@@ -76,6 +76,8 @@ class Cyr2LatProfile {
class AppSettings { class AppSettings {
static const Object _unset = Object(); static const Object _unset = Object();
static const String stadiaDemo =
'51bd0381-4685-4666-bae8-48940f6d77c0';
final bool clearPathOnMaxRetry; final bool clearPathOnMaxRetry;
final bool mapShowRepeaters; final bool mapShowRepeaters;
@@ -125,6 +127,17 @@ class AppSettings {
final List<Cyr2LatProfile> cyr2latProfiles; final List<Cyr2LatProfile> cyr2latProfiles;
final String selectedCyr2latProfileId; 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<String, String> get cyr2latCharMap { Map<String, String> get cyr2latCharMap {
final profile = cyr2latProfiles.firstWhere( final profile = cyr2latProfiles.firstWhere(
(p) => p.id == selectedCyr2latProfileId, (p) => p.id == selectedCyr2latProfileId,
+14 -8
View File
@@ -1019,11 +1019,9 @@ class AppSettingsScreen extends StatelessWidget {
} }
String _mapApiKeySummary(BuildContext context, AppSettings settings) { String _mapApiKeySummary(BuildContext context, AppSettings settings) {
final apiKey = settings.mapTileApiKey?.trim(); return context.l10n.appSettings_stadiaApiKeyConfigured(
if (apiKey == null || apiKey.isEmpty) { _maskApiKey(settings.effectiveMapTileApiKey),
return context.l10n.appSettings_stadiaApiKeyRequired; );
}
return context.l10n.appSettings_stadiaApiKeyConfigured(_maskApiKey(apiKey));
} }
String _maskApiKey(String value) { String _maskApiKey(String value) {
@@ -1153,9 +1151,13 @@ class AppSettingsScreen extends StatelessWidget {
BuildContext context, BuildContext context,
AppSettingsService settingsService, AppSettingsService settingsService,
) { ) {
final controller = TextEditingController( final currentApiKey = settingsService.settings.mapTileApiKey?.trim() ?? '';
text: settingsService.settings.mapTileApiKey ?? '', final maskedApiKey = _maskApiKey(
currentApiKey.isEmpty
? AppSettings.stadiaDemo
: currentApiKey,
); );
final controller = TextEditingController(text: maskedApiKey);
showDialog( showDialog(
context: context, context: context,
builder: (dialogContext) => AlertDialog( builder: (dialogContext) => AlertDialog(
@@ -1173,6 +1175,7 @@ class AppSettingsScreen extends StatelessWidget {
autofocus: true, autofocus: true,
autocorrect: false, autocorrect: false,
enableSuggestions: false, enableSuggestions: false,
autofillHints: const [AutofillHints.password],
decoration: const InputDecoration( decoration: const InputDecoration(
border: OutlineInputBorder(), border: OutlineInputBorder(),
hintText: '4e1bf343-3d91-4d9c-a8e1-1234567890ab', hintText: '4e1bf343-3d91-4d9c-a8e1-1234567890ab',
@@ -1188,7 +1191,10 @@ class AppSettingsScreen extends StatelessWidget {
), ),
TextButton( TextButton(
onPressed: () async { onPressed: () async {
await settingsService.setMapTileApiKey(controller.text); final apiKey = controller.text.trim();
await settingsService.setMapTileApiKey(
apiKey == maskedApiKey ? currentApiKey : apiKey,
);
if (!dialogContext.mounted) return; if (!dialogContext.mounted) return;
Navigator.pop(dialogContext); Navigator.pop(dialogContext);
}, },
+41 -13
View File
@@ -305,8 +305,22 @@ class MapTileCacheService extends ChangeNotifier {
appSettingsService.addListener(_handleSettingsChanged); appSettingsService.addListener(_handleSettingsChanged);
} }
MapRasterSourceDefinition get source => MapRasterSourceDefinition get source {
MapRasterSourceCatalog.fromSettings(appSettingsService.settings); 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 => MapRasterEndpointDefinition get endpoint =>
MapRasterEndpointCatalog.fromSettings(appSettingsService.settings); MapRasterEndpointCatalog.fromSettings(appSettingsService.settings);
@@ -315,6 +329,26 @@ class MapTileCacheService extends ChangeNotifier {
TileBuilder? get tileBuilder => null; 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([ static const ColorFilter _darkMapFilter = ColorFilter.matrix([
-0.0850, -0.0850,
-0.2861, -0.2861,
@@ -345,7 +379,6 @@ class MapTileCacheService extends ChangeNotifier {
}; };
Widget buildTileLayer(BuildContext context, {double opacity = 1}) { Widget buildTileLayer(BuildContext context, {double opacity = 1}) {
final source = this.source;
Widget layer = TileLayer( Widget layer = TileLayer(
urlTemplate: urlTemplate, urlTemplate: urlTemplate,
tileProvider: tileProvider, tileProvider: tileProvider,
@@ -354,12 +387,10 @@ class MapTileCacheService extends ChangeNotifier {
maxZoom: 19, maxZoom: 19,
); );
final shouldApplyDarkFilter = final shouldApplyDarkFilter = shouldApplyDarkFilterForSettings(
source == MapRasterSourceCatalog.osmDark || appSettingsService.settings,
source == MapRasterSourceCatalog.outdoorsDark || Theme.of(context).brightness,
source == MapRasterSourceCatalog.osmBrightDark || );
(source == MapRasterSourceCatalog.osmAuto &&
Theme.of(context).brightness == Brightness.dark);
if (shouldApplyDarkFilter) { if (shouldApplyDarkFilter) {
layer = ColorFiltered(colorFilter: _darkMapFilter, child: layer); layer = ColorFiltered(colorFilter: _darkMapFilter, child: layer);
@@ -608,12 +639,9 @@ class MapTileCacheService extends ChangeNotifier {
return 'https://tile.openstreetmap.org/{z}/{x}/{y}.png'; return 'https://tile.openstreetmap.org/{z}/{x}/{y}.png';
} }
final endpoint = MapRasterEndpointCatalog.fromSettings(settings); final endpoint = MapRasterEndpointCatalog.fromSettings(settings);
final apiKey = settings.mapTileApiKey?.trim(); final apiKey = settings.effectiveMapTileApiKey;
final base = final base =
'https://${endpoint.host}/tiles/${source.id}/{z}/{x}/{y}${endpoint.scaleSuffix}.png'; '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; final query = Uri(queryParameters: {'api_key': apiKey}).query;
return '$base?$query'; return '$base?$query';
} }