Initialisation
FMTC is licensed under GPL-v3.
If you're developing an application that isn't licensed under GPL, this affects you and your application's legal right to distribution. For more information, please see (Proprietary) Licensing.
FMTC relies on a self-contained 'environment', called a Backends, that requires initialisation (and configuration) before it can be used. This allows the backend to start any necessary seperate threads/isolates, load any prerequisites, and open and maintain a connection to a database. This environment/backend is then accessible internally through a() singleton, so initialisation is not required again.
Initialisation
Initialisation should be performed before any other FMTC or backend methods are used, and so it is usually placed just before runApp
, in the main
method. This shouldn't have any significant effect on application startup time.
If initialising in the main
method before runApp
is called, ensure you also call WidgetsFlutterBinding.ensureInitialised()
prior to the backend initialisation.
Do not call any other FMTC methods before initialisation. Doing so will cause a RootUnavailable
error to be thrown.
Do not attempt to initialise the same backend multiple times, or initialise multiple backends simultaenously. Doing so will cause a RootAlreadyInitialised
error to be thrown.
Avoid using FMTC in a seperate thread/Isolate
. FMTC backends already make extensive use of multi-threading to improve performance.
If it is essential to use FMTC in a seperate thread, ensure that the initialisation is called in the thread where it is used. Be cautious of using FMTC manually across multiple threads simultaneously, as backends may not properly support this, and unexpected behaviours may occur.
Uninitialisation
It is also possible to un-initialise FMTC and the current backend. This should be rarely required, but can be performed through the uninitialise
method of the backend if required. Initialisation is possible after manual uninitialisation.
Backends
FMTC supports attachment of any custom storage mechanism, through an FMTCBackend
. This allows users to pick their favourite database engine, or conduct in-memory testing.
Only one backend is built-into FMTC: the FMTCObjectBoxBackend
. This backend uses the ObjectBox library to store data.
ObjectBox has a complex license model - the build time dependency is open-source, whilst the native library runtime only dependency is under a closed-source (but relatively relaxed) license (that is liable to change at ObjectBox's will).
This is not an issue for the majority of applications. However, ObjectBox is known to be (rightly or wrongly) banned as a dependency from apps on F-Droid (last checked September 2024).
Future updates to FMTC will implement alternative backends using other libraries, and the default/preferred backend may indeed change in future.
For more information, please see: https://github.com/JaffaKetchup/flutter_map_tile_caching/issues/167.
Last updated