flutter_map_mbtiles

Raster MBTiles TileProvider for flutter_map.

  • Supported raster tiles: jpg, png, webp
  • If you want to use pbf vector tiles you can use vector_map_tiles_mbtiles.
  • Web is not supported because of its lacking SQLite support.

Pub Version likes Pub Points Pub Downloads

GitHub last commit stars GitHub issues codecov

Getting started

pubspec.yaml

dependencies:
  flutter_map: ^8.0.0         # in case you don't have it yet
  flutter_map_mbtiles: ^1.1.0 # this package

The underlying mbtiles package uses native assets to bundle SQLite, so no extra setup is needed on supported platforms. Please check its Getting started guide if you run into build problems.

Usage

// Provide the path of the MBTiles file to the tile provider.
// The file must be on your file system and the app must have the permission
// to access it. The file can't be in your assets.
final tileProvider = MbTilesTileProvider.fromPath(
  path: 'path/to/file.mbtiles',
);

@override
Widget build(BuildContext context) {
  return FlutterMap(
    options: const MapOptions(),
    children: [
      TileLayer(
        tileProvider: tileProvider,
      ),
    ],
  );
}

@override
void dispose() {
  // closes the MBTiles database
  tileProvider.dispose();
  super.dispose();
}

Use an existing MbTiles instance

Alternatively, open the database yourself and pass it to the tile provider. You are then responsible for closing it. MbTiles is not exported by this package, add mbtiles as a direct dependency to your pubspec.yaml:

dependencies:
  mbtiles: ^0.5.0
import 'package:mbtiles/mbtiles.dart';

final mbtiles = MbTiles(path: 'path/to/file.mbtiles');
final tileProvider = MbTilesTileProvider(mbtiles: mbtiles);

// close the database when you don't need it anymore
mbtiles.close();

Additional information

If you need help you can open an issue or join the flutter_map discord server.