|
| 1 | +import 'package:flutter/material.dart'; |
1 | 2 | import 'package:flutter_map/flutter_map.dart'; |
2 | 3 | import 'package:http/http.dart'; |
3 | 4 | import 'package:http/retry.dart'; |
| 5 | +import 'package:url_launcher/url_launcher.dart'; |
4 | 6 |
|
5 | | -final httpClient = RetryClient(Client()); |
| 7 | +final _httpClient = RetryClient(Client()); |
6 | 8 |
|
7 | | -// TODO: This causes unneccessary rebuilding |
8 | | -TileLayer get openStreetMapTileLayer => TileLayer( |
9 | | - urlTemplate: 'https://tile.openstreetmap.org/{z}/{x}/{y}.png', |
10 | | - userAgentPackageName: 'dev.fleaflet.flutter_map.demo', |
11 | | - tileProvider: NetworkTileProvider(httpClient: httpClient), |
12 | | - maxNativeZoom: 19, |
| 9 | +class PrimaryTileLayer extends StatelessWidget { |
| 10 | + const PrimaryTileLayer({super.key, this.showAttributionImmediately = false}); |
| 11 | + |
| 12 | + final bool showAttributionImmediately; |
| 13 | + |
| 14 | + @override |
| 15 | + Widget build(BuildContext context) { |
| 16 | + return Stack( |
| 17 | + children: [ |
| 18 | + TileLayer( |
| 19 | + urlTemplate: 'https://tile.openstreetmap.org/{z}/{x}/{y}.png', |
| 20 | + userAgentPackageName: 'dev.fleaflet.flutter_map.demo', |
| 21 | + tileProvider: NetworkTileProvider(httpClient: _httpClient), |
| 22 | + maxNativeZoom: 19, |
| 23 | + ), |
| 24 | + RichAttributionWidget( |
| 25 | + popupInitialDisplayDuration: showAttributionImmediately |
| 26 | + ? const Duration(seconds: 5) |
| 27 | + : Duration.zero, |
| 28 | + animationConfig: const ScaleRAWA(), |
| 29 | + attributions: [ |
| 30 | + TextSourceAttribution( |
| 31 | + 'OpenStreetMap contributors', |
| 32 | + onTap: () async => |
| 33 | + launchUrl(Uri.parse('https://openstreetmap.org/copyright')), |
| 34 | + ), |
| 35 | + ], |
| 36 | + ), |
| 37 | + ], |
13 | 38 | ); |
| 39 | + } |
| 40 | +} |
0 commit comments