Add the region map, permanent attribution and the Sources screen
Puts a MapLibre map on screen framed on the region, with the credit obligations that come with showing third-party data satisfied structurally rather than by remembering to add a label. The base map style comes from MAP_STYLE_URL, and with no key configured the app generates a fallback style from the region's own bounding box: a flat background and the extent outline, no network sources at all. That keeps a fresh clone runnable offline without pulling in a boundary dataset that would carry its own licence, and it deliberately looks like a placeholder so it is not mistaken for a finished map. Attribution is driven by what is actually rendered. The bar lists the credits for the active sources only, because crediting OpenStreetMap while showing the fallback style would be a false attribution, and it says plainly when no base map is configured. It sits below the map rather than floating over it so no map control or gesture overlay can occlude a credit that the ODbL and CC BY-SA terms require to be visible. The Sources screen leads with the independence disclaimer, before the sources it qualifies, so a reader who stops after the first screenful has still seen it. Sources with no stated licence — ARPA publishes none for the alert bulletin — say so explicitly rather than being shown bare or given an invented one. A separate note explains that the rendered radar frames inherit CC BY-SA from the DPC source data. Also declares the INTERNET permission in the main manifest: Flutter injects it into the debug and profile manifests only, so a release build would otherwise fail every request on device. Verified: analyze clean, 66 tests passing, appbundle builds with the native MapLibre plugin. Not verified visually — this machine has no Android device or emulator image, so nobody has watched the map render. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,84 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../../core/region/region_config.dart';
|
||||
import '../../l10n/app_localizations.dart';
|
||||
import '../sources/sources_screen.dart';
|
||||
|
||||
/// Always-visible credits for whatever is currently drawn on the map.
|
||||
///
|
||||
/// This is a licence obligation, not decoration: OpenStreetMap's ODbL and
|
||||
/// Radar-DPC's CC BY-SA both require the credit to be shown wherever the data
|
||||
/// is. It is therefore never collapsed, hidden behind a gesture, or covered by
|
||||
/// another control, and it lists only the sources actually on screen — crediting
|
||||
/// OpenStreetMap while showing the offline fallback would be a false claim.
|
||||
class AttributionBar extends StatelessWidget {
|
||||
const AttributionBar({
|
||||
required this.region,
|
||||
required this.activeSourceIds,
|
||||
this.showBaseMapNotice = false,
|
||||
super.key,
|
||||
});
|
||||
|
||||
final RegionConfig region;
|
||||
|
||||
/// Attribution ids, matching `attributions[].id` in the region config, for
|
||||
/// the data currently rendered.
|
||||
final Set<String> activeSourceIds;
|
||||
|
||||
/// Whether to say that no base map is configured. True when the offline
|
||||
/// fallback style is in use, so the placeholder is never mistaken for a map.
|
||||
final bool showBaseMapNotice;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final l10n = AppLocalizations.of(context);
|
||||
final theme = Theme.of(context);
|
||||
|
||||
final credits = region.attributions
|
||||
.where((attribution) => activeSourceIds.contains(attribution.id))
|
||||
.map((attribution) => attribution.text)
|
||||
.toList(growable: false);
|
||||
|
||||
final parts = <String>[
|
||||
if (showBaseMapNotice) l10n.baseMapNotConfigured,
|
||||
...credits,
|
||||
];
|
||||
|
||||
return Material(
|
||||
color: theme.colorScheme.surface.withValues(alpha: 0.85),
|
||||
child: InkWell(
|
||||
onTap: () => Navigator.of(
|
||||
context,
|
||||
).push(MaterialPageRoute<void>(builder: (_) => const SourcesScreen())),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 6),
|
||||
child: Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: Text(
|
||||
parts.join(' · '),
|
||||
style: theme.textTheme.bodySmall,
|
||||
maxLines: 2,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Text(
|
||||
l10n.sourcesLink,
|
||||
style: theme.textTheme.bodySmall?.copyWith(
|
||||
color: theme.colorScheme.primary,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
Icon(
|
||||
Icons.chevron_right,
|
||||
size: 16,
|
||||
color: theme.colorScheme.primary,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,114 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import '../../core/config/env.dart';
|
||||
import '../../core/region/region_config.dart';
|
||||
|
||||
/// Which base map the app is showing, and therefore which credits are owed.
|
||||
enum BaseMapKind {
|
||||
/// A real vector base map from [Env.mapStyleUrl]. Carries OpenStreetMap data,
|
||||
/// so the ODbL credit is mandatory.
|
||||
configured,
|
||||
|
||||
/// The bundled fallback: a flat background and the region outline, drawn from
|
||||
/// the region config. Contains no third-party map data, so crediting
|
||||
/// OpenStreetMap here would be a false attribution.
|
||||
offlineFallback,
|
||||
}
|
||||
|
||||
/// Resolves the MapLibre style the app should load.
|
||||
///
|
||||
/// With no `MAP_STYLE_URL` configured the app must still run — offline, in
|
||||
/// tests, and on a fresh clone with no credentials — so it falls back to a
|
||||
/// style generated from the region's own bounding box.
|
||||
class MapStyle {
|
||||
const MapStyle({required this.kind, required this.styleString});
|
||||
|
||||
factory MapStyle.forRegion(RegionConfig region) {
|
||||
if (Env.hasMapStyle) {
|
||||
return MapStyle(
|
||||
kind: BaseMapKind.configured,
|
||||
styleString: Env.mapStyleUrl,
|
||||
);
|
||||
}
|
||||
return MapStyle(
|
||||
kind: BaseMapKind.offlineFallback,
|
||||
styleString: buildFallbackStyle(region),
|
||||
);
|
||||
}
|
||||
|
||||
final BaseMapKind kind;
|
||||
|
||||
/// Either a style URL or an inline MapLibre style document; the map widget
|
||||
/// accepts both.
|
||||
final String styleString;
|
||||
|
||||
/// Attribution ids owed by the base map itself, as they appear in the region
|
||||
/// config. The radar and forecast layers add their own on top of these.
|
||||
Set<String> get attributionIds => switch (kind) {
|
||||
BaseMapKind.configured => const <String>{'osm'},
|
||||
BaseMapKind.offlineFallback => const <String>{},
|
||||
};
|
||||
|
||||
/// Builds a self-contained MapLibre style: a flat background plus the region
|
||||
/// bounding box, with no network sources at all.
|
||||
///
|
||||
/// The outline is deliberately the *bounding box*, not the administrative
|
||||
/// boundary. A real boundary would need a third-party dataset with its own
|
||||
/// licence, and would make the fallback look like a finished map when it is
|
||||
/// a placeholder.
|
||||
static String buildFallbackStyle(RegionConfig region) {
|
||||
final b = region.bounds;
|
||||
final ring = <List<double>>[
|
||||
<double>[b.west, b.south],
|
||||
<double>[b.east, b.south],
|
||||
<double>[b.east, b.north],
|
||||
<double>[b.west, b.north],
|
||||
<double>[b.west, b.south],
|
||||
];
|
||||
|
||||
final style = <String, Object?>{
|
||||
'version': 8,
|
||||
'name': 'Nuvolari offline fallback',
|
||||
'sources': <String, Object?>{
|
||||
'region-extent': <String, Object?>{
|
||||
'type': 'geojson',
|
||||
'data': <String, Object?>{
|
||||
'type': 'Feature',
|
||||
'properties': <String, Object?>{'id': region.id},
|
||||
'geometry': <String, Object?>{
|
||||
'type': 'Polygon',
|
||||
'coordinates': <Object?>[ring],
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
'layers': <Object?>[
|
||||
<String, Object?>{
|
||||
'id': 'background',
|
||||
'type': 'background',
|
||||
'paint': <String, Object?>{'background-color': '#0B1720'},
|
||||
},
|
||||
<String, Object?>{
|
||||
'id': 'region-extent-fill',
|
||||
'type': 'fill',
|
||||
'source': 'region-extent',
|
||||
'paint': <String, Object?>{
|
||||
'fill-color': '#13303F',
|
||||
'fill-opacity': 0.7,
|
||||
},
|
||||
},
|
||||
<String, Object?>{
|
||||
'id': 'region-extent-outline',
|
||||
'type': 'line',
|
||||
'source': 'region-extent',
|
||||
'paint': <String, Object?>{
|
||||
'line-color': '#4FA3D1',
|
||||
'line-width': 1.5,
|
||||
},
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
return jsonEncode(style);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,111 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:maplibre_gl/maplibre_gl.dart';
|
||||
|
||||
import '../../core/config/env.dart';
|
||||
import '../../core/region/region_config.dart';
|
||||
import '../../core/region/region_repository.dart';
|
||||
import '../../l10n/app_localizations.dart';
|
||||
import 'attribution_bar.dart';
|
||||
import 'map_style.dart';
|
||||
|
||||
/// The radar map.
|
||||
///
|
||||
/// Milestone 2 renders the base map, frames it on the region and keeps the
|
||||
/// attribution visible. The radar image layers and the timeline arrive in
|
||||
/// milestone 3.
|
||||
class RadarMapScreen extends ConsumerWidget {
|
||||
const RadarMapScreen({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final l10n = AppLocalizations.of(context);
|
||||
final region = ref.watch(regionConfigProvider);
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(title: Text(l10n.appTitle)),
|
||||
body: switch (region) {
|
||||
AsyncData(:final value) => _MapWithAttribution(region: value),
|
||||
AsyncError(:final error) => Center(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(24),
|
||||
child: Text('${l10n.dataUnavailable}\n$error'),
|
||||
),
|
||||
),
|
||||
_ => Center(child: Text(l10n.loading)),
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _MapWithAttribution extends StatelessWidget {
|
||||
const _MapWithAttribution({required this.region});
|
||||
|
||||
final RegionConfig region;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final l10n = AppLocalizations.of(context);
|
||||
final style = MapStyle.forRegion(region);
|
||||
|
||||
return Column(
|
||||
children: [
|
||||
if (Env.isDemoMode)
|
||||
MaterialBanner(
|
||||
content: Text(l10n.demoModeBanner),
|
||||
actions: const [SizedBox.shrink()],
|
||||
),
|
||||
Expanded(
|
||||
child: _RegionMap(region: region, style: style),
|
||||
),
|
||||
// Outside the map rather than floating over it, so the credit can never
|
||||
// be occluded by a map control or a gesture overlay.
|
||||
AttributionBar(
|
||||
region: region,
|
||||
activeSourceIds: style.attributionIds,
|
||||
showBaseMapNotice: style.kind == BaseMapKind.offlineFallback,
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _RegionMap extends StatelessWidget {
|
||||
const _RegionMap({required this.region, required this.style});
|
||||
|
||||
final RegionConfig region;
|
||||
final MapStyle style;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final center = region.map.center;
|
||||
final zoom = region.map.zoom;
|
||||
final bounds = region.bounds;
|
||||
|
||||
return MapLibreMap(
|
||||
styleString: style.styleString,
|
||||
initialCameraPosition: CameraPosition(
|
||||
target: LatLng(center.latitude, center.longitude),
|
||||
zoom: zoom.initial,
|
||||
),
|
||||
minMaxZoomPreference: MinMaxZoomPreference(zoom.min, zoom.max),
|
||||
// Panning is confined to the region: this app has data for Piedmont and
|
||||
// nowhere else, so letting the user drift away would only ever show an
|
||||
// empty map.
|
||||
cameraTargetBounds: CameraTargetBounds(
|
||||
LatLngBounds(
|
||||
southwest: LatLng(bounds.south, bounds.west),
|
||||
northeast: LatLng(bounds.north, bounds.east),
|
||||
),
|
||||
),
|
||||
// Kept enabled on top of our own attribution bar: some tile providers
|
||||
// require the plugin's own attribution control, and a duplicated credit
|
||||
// is harmless where a missing one is a licence breach.
|
||||
attributionButtonPosition: AttributionButtonPosition.bottomRight,
|
||||
compassEnabled: false,
|
||||
rotateGesturesEnabled: false,
|
||||
tiltGesturesEnabled: false,
|
||||
myLocationEnabled: false,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,185 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:url_launcher/url_launcher.dart';
|
||||
|
||||
import '../../core/region/region_config.dart';
|
||||
import '../../core/region/region_repository.dart';
|
||||
import '../../l10n/app_localizations.dart';
|
||||
|
||||
/// Sources, licences and the independence disclaimer.
|
||||
///
|
||||
/// Reachable from the attribution bar on every screen that shows data. The
|
||||
/// content is driven by the region config so a new region cannot ship without
|
||||
/// its credits.
|
||||
class SourcesScreen extends ConsumerWidget {
|
||||
const SourcesScreen({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final l10n = AppLocalizations.of(context);
|
||||
final region = ref.watch(regionConfigProvider);
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(title: Text(l10n.sourcesTitle)),
|
||||
body: switch (region) {
|
||||
AsyncData(:final value) => _SourcesBody(region: value),
|
||||
AsyncError(:final error) => Center(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(24),
|
||||
child: Text('${l10n.dataUnavailable}\n$error'),
|
||||
),
|
||||
),
|
||||
_ => Center(child: Text(l10n.loading)),
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _SourcesBody extends StatelessWidget {
|
||||
const _SourcesBody({required this.region});
|
||||
|
||||
final RegionConfig region;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final l10n = AppLocalizations.of(context);
|
||||
final theme = Theme.of(context);
|
||||
|
||||
return ListView(
|
||||
padding: const EdgeInsets.symmetric(vertical: 8),
|
||||
children: [
|
||||
// The disclaimer comes first, before the sources it qualifies: a reader
|
||||
// who stops after the first screenful must still have seen it.
|
||||
_Card(
|
||||
icon: Icons.info_outline,
|
||||
title: l10n.sourcesDisclaimerTitle,
|
||||
body: l10n.sourcesDisclaimerBody,
|
||||
),
|
||||
|
||||
_SectionHeader(l10n.sourcesDataSection),
|
||||
for (final attribution in region.attributions)
|
||||
_AttributionTile(attribution: attribution),
|
||||
|
||||
_Card(
|
||||
icon: Icons.copyright_outlined,
|
||||
title: l10n.sourcesShareAlikeTitle,
|
||||
body: l10n.sourcesShareAlikeBody,
|
||||
),
|
||||
|
||||
Padding(
|
||||
padding: const EdgeInsets.fromLTRB(16, 8, 16, 24),
|
||||
child: OutlinedButton.icon(
|
||||
onPressed: () => _open(region.alerts.officialBulletinUrl),
|
||||
icon: const Icon(Icons.open_in_new),
|
||||
label: Text(l10n.sourcesOfficialBulletin),
|
||||
),
|
||||
),
|
||||
|
||||
Padding(
|
||||
padding: const EdgeInsets.fromLTRB(16, 0, 16, 24),
|
||||
child: Text(
|
||||
region.displayName,
|
||||
style: theme.textTheme.bodySmall?.copyWith(
|
||||
color: theme.colorScheme.outline,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _AttributionTile extends StatelessWidget {
|
||||
const _AttributionTile({required this.attribution});
|
||||
|
||||
final Attribution attribution;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final l10n = AppLocalizations.of(context);
|
||||
final license = attribution.license;
|
||||
|
||||
return ListTile(
|
||||
title: Text(attribution.text),
|
||||
subtitle: Text(
|
||||
license == null
|
||||
? l10n.sourcesNoLicenseStated
|
||||
: l10n.sourcesLicenseLabel(license),
|
||||
),
|
||||
trailing: IconButton(
|
||||
icon: const Icon(Icons.open_in_new),
|
||||
tooltip: l10n.openLink,
|
||||
onPressed: () => _open(attribution.url),
|
||||
),
|
||||
onTap: () => _open(attribution.url),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _SectionHeader extends StatelessWidget {
|
||||
const _SectionHeader(this.title);
|
||||
|
||||
final String title;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = Theme.of(context);
|
||||
|
||||
return Padding(
|
||||
padding: const EdgeInsets.fromLTRB(16, 16, 16, 8),
|
||||
child: Text(
|
||||
title,
|
||||
style: theme.textTheme.titleSmall?.copyWith(
|
||||
color: theme.colorScheme.primary,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _Card extends StatelessWidget {
|
||||
const _Card({required this.icon, required this.title, required this.body});
|
||||
|
||||
final IconData icon;
|
||||
final String title;
|
||||
final String body;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = Theme.of(context);
|
||||
|
||||
return Card(
|
||||
margin: const EdgeInsets.fromLTRB(16, 8, 16, 8),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Icon(icon, color: theme.colorScheme.primary),
|
||||
const SizedBox(width: 12),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(title, style: theme.textTheme.titleSmall),
|
||||
const SizedBox(height: 4),
|
||||
Text(body, style: theme.textTheme.bodyMedium),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// Opens [url] in the browser, ignoring a failure to launch.
|
||||
///
|
||||
/// A dead link is a poor experience but not a reason to crash the screen the
|
||||
/// disclaimer lives on.
|
||||
Future<void> _open(String url) async {
|
||||
final uri = Uri.tryParse(url);
|
||||
if (uri == null) return;
|
||||
await launchUrl(uri, mode: LaunchMode.externalApplication);
|
||||
}
|
||||
Reference in New Issue
Block a user