flutter_map_cache 1.0.0 copy "flutter_map_cache: ^1.0.0" to clipboard
flutter_map_cache: ^1.0.0 copied to clipboard

A slim yet powerful caching plugin for flutter_map tile layers.

flutter_map_cache #

A slim yet powerful caching plugin for flutter_map tile layers.

Pub Likes Pub Points Pub Popularity Pub Version

GitHub last commit GitHub issues GitHub Repo stars

Features #

The package is using dio with the dio_cache_interceptor package and supports the storage backend that you like.

Supported storage backends are:

Getting started #

Add the packages you want to use to your pubspec.yaml file.

Only add the packages for the backend you want to use.

dependencies:
  flutter_map: ^5.0.0 # in case you don't have it yet 
  flutter_map_cache: ^1.0.0 # this package

  dio_cache_interceptor_db_store: ^5.1.0 # drift
  sqlite3_flutter_libs: ^0.5.15 # drift

  dio_cache_interceptor_file_store: ^1.2.2 # file system

  dio_cache_interceptor_hive_store: ^3.2.1 # hive

  dio_cache_interceptor_objectbox_store: ^1.1.1 # objectbox
  objectbox_flutter_libs: ^1.4.1 # objectbox  

Usage #

Using the cache is easy. Here is an example how to use the Hive backend:

First get the app data directory (i.e. with the path_provider package):

import 'package:path_provider/path_provider.dart';

Future<String> getPath() async {
  final dataDirectory = await getApplicationDocumentsDirectory();
  return dataDirectory.path;
}

Then use the directory path to initialize the HiveCacheStore:

@override
Widget build(BuildContext context) {
  return FlutterMap(
    options: MapOptions(),
    children: [
      TileLayer(
        urlTemplate: 'https://tile.openstreetmap.org/{z}/{x}/{y}.png',
        tileProvider: CachedTileProvider(
          store: HiveCacheStore(
            '$path${Platform.pathSeparator}HiveCacheStore',
            hiveBoxName: 'HiveCacheStore',
          ),
        ),
      ),
    ],
  );
}

Additional information #

Pull requests are welcome. If you want to add support for another storage backend you can check out dio_cache_interceptor.