FMTC Docs
v8
Ask or search…
K
Links

Using Roots & Stores

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 Isar 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 metadata).

Chaining

Once you can access FlutterMapTileCaching.instance after Initialisation, chaining of methods and accessors is used to access functionality.
  1. 1.
    Base Chains are used as an intermediate step to access functionality on Roots and Stores
  2. 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.
Without Automatic Creation
With Automatic Synchronous Creation
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