Skip to content

Commit bb1755d

Browse files
mikolaj-jalochasimon-the-shark
authored andcommitted
#221 - add cache support for map tiles
1 parent d824cd7 commit bb1755d

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

lib/config/map_view_config.dart

+6
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,12 @@ abstract class OpenStreetMapConfig {
5151
Platform.isIOS ? "com.solvro.ToPwr" : "com.solvro.topwr";
5252
}
5353

54+
abstract class MapCacheConfig {
55+
// in days
56+
static const cacheDuration = 30;
57+
static const cacheBoxName = "HiveMapCacheStore";
58+
}
59+
5460
abstract class BuildingSearchConfig {
5561
static const buildingCodeSeperator = "-";
5662
}

lib/features/map_view/widgets/map_widget.dart

+9-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
import "package:dio_cache_interceptor_hive_store/dio_cache_interceptor_hive_store.dart";
12
import "package:flutter/material.dart";
23
import "package:flutter_map/flutter_map.dart";
3-
import "package:flutter_map_cancellable_tile_provider/flutter_map_cancellable_tile_provider.dart";
4+
import "package:flutter_map_cache/flutter_map_cache.dart";
45
import "package:flutter_riverpod/flutter_riverpod.dart";
56

67
import "../../../config/map_view_config.dart";
@@ -38,7 +39,13 @@ class MapWidget<T extends GoogleNavigable> extends ConsumerWidget {
3839
TileLayer(
3940
urlTemplate: OpenStreetMapConfig.tileUrl,
4041
userAgentPackageName: OpenStreetMapConfig.userAgent,
41-
tileProvider: CancellableNetworkTileProvider(),
42+
tileProvider: CachedTileProvider(
43+
maxStale: const Duration(days: MapCacheConfig.cacheDuration),
44+
store: HiveCacheStore(
45+
null,
46+
hiveBoxName: MapCacheConfig.cacheBoxName,
47+
),
48+
),
4249
),
4350
MarkersConsumerLayer<T>(),
4451
const MyLocationLayer(),

pubspec.yaml

+2
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,14 @@ dependencies:
7373
flutter_map_cancellable_tile_provider: ^3.0.2
7474
flutter_map_location_marker: ^9.1.1
7575
flutter_map_compass: ^1.0.3
76+
flutter_map_cache: ^1.3.0
7677
hooks_riverpod: ^2.5.2
7778
firebase_crashlytics: ^4.1.2
7879
firebase_analytics: ^11.3.2
7980
firebase_core: ^3.5.0
8081
firebase_performance: ^0.10.0+7
8182
firebase_messaging: ^15.1.2
83+
dio_cache_interceptor_hive_store: ^3.2.1
8284

8385
dev_dependencies:
8486
flutter_test:

0 commit comments

Comments
 (0)