Skip to content

Commit

Permalink
Added basic tile caching
Browse files Browse the repository at this point in the history
  • Loading branch information
TKFRvisionOfficial committed Jan 24, 2023
1 parent c7a66ea commit 32e8161
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 3 deletions.
20 changes: 17 additions & 3 deletions lib/widgets/recording_map.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_map/flutter_map.dart';
Expand Down Expand Up @@ -59,9 +60,9 @@ class _RecordingMapState extends State<RecordingMap> {
nonRotatedChildren: const [_MapAttribution()],
children: [
TileLayer(
urlTemplate: "https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png",
subdomains: const ["a", "b", "c"],
userAgentPackageName: "solutions.tlm.stasi",
urlTemplate: "https://tile.openstreetmap.org/{z}/{x}/{y}.png",
userAgentPackageName: "solutions.dvb.stasi",
tileProvider: _CachedTileProvider(),
tileBuilder: darkModeTileBuilder,
backgroundColor: Colors.black54,
),
Expand Down Expand Up @@ -190,3 +191,16 @@ LatLngBounds _getBoundsFromPoints(List<LatLng> points) {

return bounds;
}

class _CachedTileProvider extends TileProvider {

@override
ImageProvider<Object> getImage(Coords<num> coords, TileLayer options) =>
CachedNetworkImageProvider(
getTileUrl(coords, options),
// im not sure if it respects the cache-control headers
// let's hope it does
headers: headers,
);

}
70 changes: 70 additions & 0 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,27 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.0"
cached_network_image:
dependency: "direct main"
description:
name: cached_network_image
url: "https://pub.dartlang.org"
source: hosted
version: "3.2.3"
cached_network_image_platform_interface:
dependency: transitive
description:
name: cached_network_image_platform_interface
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.0"
cached_network_image_web:
dependency: transitive
description:
name: cached_network_image_web
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.2"
characters:
dependency: transitive
description:
Expand All @@ -45,6 +66,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "1.16.0"
crypto:
dependency: transitive
description:
name: crypto
url: "https://pub.dartlang.org"
source: hosted
version: "3.0.2"
cupertino_icons:
dependency: "direct main"
description:
Expand Down Expand Up @@ -78,6 +106,20 @@ packages:
description: flutter
source: sdk
version: "0.0.0"
flutter_blurhash:
dependency: transitive
description:
name: flutter_blurhash
url: "https://pub.dartlang.org"
source: hosted
version: "0.7.0"
flutter_cache_manager:
dependency: "direct main"
description:
name: flutter_cache_manager
url: "https://pub.dartlang.org"
source: hosted
version: "3.3.0"
flutter_lints:
dependency: "direct dev"
description:
Expand Down Expand Up @@ -193,6 +235,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.0"
octo_image:
dependency: transitive
description:
name: octo_image
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.2"
path:
dependency: "direct main"
description:
Expand Down Expand Up @@ -249,6 +298,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.3"
pedantic:
dependency: transitive
description:
name: pedantic
url: "https://pub.dartlang.org"
source: hosted
version: "1.11.1"
petitparser:
dependency: transitive
description:
Expand Down Expand Up @@ -312,6 +368,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "3.1.0"
rxdart:
dependency: transitive
description:
name: rxdart
url: "https://pub.dartlang.org"
source: hosted
version: "0.27.7"
shared_preferences:
dependency: "direct main"
description:
Expand Down Expand Up @@ -513,6 +576,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "3.0.1"
uuid:
dependency: transitive
description:
name: uuid
url: "https://pub.dartlang.org"
source: hosted
version: "3.0.7"
vector_math:
dependency: transitive
description:
Expand Down
2 changes: 2 additions & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ dependencies:
flutter_map: ^3.1.0
latlong2: ^0.8.1
url_launcher: ^6.1.7
flutter_cache_manager: ^3.3.0
cached_network_image: ^3.2.3

dev_dependencies:
flutter_test:
Expand Down

0 comments on commit 32e8161

Please sign in to comment.