FMTC Docs
Project Links💝 Support Me
v8
v8
  • flutter_map_tile_caching
  • Is FMTC Right For Me?
  • Get Started
    • Quickstart
    • Installation
    • Additional Setup
    • Example Application
  • Usage
    • Initialisation
    • Using Roots & Stores
      • Management
      • Statistics
      • Metadata
      • Recovery
      • Migrator (v6 -> v7)
    • flutter_map Integration
    • Global Settings
    • Full API Reference
  • Bulk Downloading
    • Introduction
    • 1️⃣Create A Region
    • 2️⃣Prepare For Downloading
    • 3️⃣Start In Foreground
      • Buffering
      • 4️⃣Listen For Progress
    • 3️⃣Start In Background
      • Limitations
    • Cancel Download
  • Import & Export
    • Introduction
    • Importing
    • Exporting
  • Migration
    • v7 -> v8 Migration
    • v6 -> v7 Migration
  • Known Issues
  • Credits
  • flutter_map Docs
Powered by GitBook

© Luka Stillingfleet (JaffaKetchup)

On this page
  • How It Works
  • Chaining
  • Base Chains
  • Additional Chains

Was this helpful?

Export as PDF
  1. Usage

Using Roots & Stores

PreviousInitialisationNextManagement

Last updated 2 years ago

Was this helpful?

How It Works

FMTC uses Roots and Stores to structure it's data. Previously, these represented actual directories (hence the reference to directories within the codebase), but now they just represent databases.

There is usually only one root (formed of a directory and some miscellaneous databases) per application, which contains multiple stores (formed of a single database holding a descriptor, multiple tiles, and ).

Chaining

Once you can access FlutterMapTileCaching.instance after Initialisation, chaining of methods and accessors is used to access functionality.

  1. Base Chains are used as an intermediate step to access functionality on Roots and Stores

  2. Additional Chains are added to Base Chains to reach the actual functionality.

Base Chains

To get the Root, chain on rootDirectory (the name of the accessor is a remnant leftover from previous versions).

FlutterMapTileCaching.instance.rootDirectory;

To get a Store, there are two possible methods. FMTC does not use code generation, so store names are flexible, and so use Strings to access the Store.

This is the recommended method. Always use this method where possible.

call()/() gets a StoreDirectory by the name inside the parentheses.

Note that the store will not be automatically created once accessed, as this requires asynchronous tasks, so it is important to create the store manually (if necessary).

final store = FlutterMapTileCaching.instance('storeName');
await store.manage.create(); // Create the store if necessary

Examples in this documentation will usually assume that the stores are already created/ready.

This method is not recommended, for the reasons listed below. Prefer using Without Automatic Creation wherever possible.

  • It is synchronous and therefore blocks the main thread

  • It results in hard to trace code, as the creation calls are no longer obvious

  • It encourages minimizing accesses to increase performance, which is against the philosophy of the chaining strategy

[] gets a StoreDirectory by the name inside the parenthesis.

Note that the store will be automatically created once accessed, although it will be done synchronously in a way that blocks the main thread.

final store = FlutterMapTileCaching.instance['storeName'];

Additional Chains

After this, you can chain any of the following members/accessors (each will be accessible on a Root, a Store, or both).

Prefer using asynchronous versions of sub-methods where possible, as these won't block the UI thread.

If running inside an isolate, or blocking the UI thread doesn't matter, use the synchronous versions wherever possible, as they have slightly better performance.

Looking to modify the underlying databases youself?

This is not recommended, as they are carefully crafted to work with FMTC internal state. But, if you've read through the FMTC code and understand it, and you need to, you may import the internal APIs usually intended for modules.

  • Import 'fmtc_module_api.dart' from the same package

Install

Isar
metadata
flutter_map Integration

manage

RootsStores

Control, modify, and configure an actual structure ('physical' directory or database) itself

stats

RootsStores

Retrieve statistics about a structure (Root or Store) itself

Isar

recovery

Roots

Recover failed bulk downloads, and prepare them to restart

import

RootsModule

Import and prepare a store from a previously exported archive file

download

Stores

Prepare, start, and manage a store's bulk downloads

metadata

Stores

A simple key-value pair store designed for storing simple, store related information

export

StoresModule

Export a store to an archive file, for future importing

migrator

Roots

Migrate the incompatible file/directory structure of a previous version