Skip to content

#221 - add cache support for map tiles #229

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions lib/config/map_view_config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ abstract class OpenStreetMapConfig {
Platform.isIOS ? "com.solvro.ToPwr" : "com.solvro.topwr";
}

abstract class MapCacheConfig {
// in days
static const cacheDuration = 30;
static const cacheBoxName = "HiveMapCacheStore";
}

abstract class BuildingSearchConfig {
static const buildingCodeSeperator = "-";
}
11 changes: 9 additions & 2 deletions lib/features/map_view/widgets/map_widget.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import "package:dio_cache_interceptor_hive_store/dio_cache_interceptor_hive_store.dart";
import "package:flutter/material.dart";
import "package:flutter_map/flutter_map.dart";
import "package:flutter_map_cancellable_tile_provider/flutter_map_cancellable_tile_provider.dart";
import "package:flutter_map_cache/flutter_map_cache.dart";
import "package:flutter_riverpod/flutter_riverpod.dart";

import "../../../config/map_view_config.dart";
Expand Down Expand Up @@ -38,7 +39,13 @@ class MapWidget<T extends GoogleNavigable> extends ConsumerWidget {
TileLayer(
urlTemplate: OpenStreetMapConfig.tileUrl,
userAgentPackageName: OpenStreetMapConfig.userAgent,
tileProvider: CancellableNetworkTileProvider(),
tileProvider: CachedTileProvider(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

future note, on web we may want to use CancellableNetworkTileProvider instead of cached one - but only a future note

maxStale: const Duration(days: MapCacheConfig.cacheDuration),
store: HiveCacheStore(
null,
hiveBoxName: MapCacheConfig.cacheBoxName,
),
),
),
MarkersConsumerLayer<T>(),
const MyLocationLayer(),
Expand Down
2 changes: 2 additions & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,14 @@ dependencies:
flutter_map_cancellable_tile_provider: ^3.0.2
flutter_map_location_marker: ^9.1.1
flutter_map_compass: ^1.0.3
flutter_map_cache: ^1.3.0
hooks_riverpod: ^2.5.2
firebase_crashlytics: ^4.1.2
firebase_analytics: ^11.3.2
firebase_core: ^3.5.0
firebase_performance: ^0.10.0+7
firebase_messaging: ^15.1.2
dio_cache_interceptor_hive_store: ^3.2.1

dev_dependencies:
flutter_test:
Expand Down