Skip to content

Commit

Permalink
#221 - add cache support for map tiles
Browse files Browse the repository at this point in the history
  • Loading branch information
mikolaj-jalocha committed Sep 25, 2024
1 parent 7663bf9 commit d8ceae2
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
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(
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

0 comments on commit d8ceae2

Please sign in to comment.