FMTCTileProvider class

Specialised TileProvider that uses a specialised ImageProvider to connect to FMTC internals and enable advanced caching/retrieval logic

To use a single or multiple stores, use the FMTCTileProvider.new constructor. See documentation on stores and otherStoresStrategy for information on usage.

To use all stores, use the FMTCTileProvider.allStores constructor. See documentation on otherStoresStrategy for information on usage.

Tip

Minimize reconstructions of this provider by constructing it outside of the build method of a widget wherever possible.

If this is not possible, because one or more properties depend on inherited data (ie. via an InheritedWidget, Provider, etc.), define and construct as many properties as possible outside of the build method.

  • Manually constructing and initialising an httpClient once is much cheaper than the FMTCTileProvider's constructors doing it automatically on every construction (every rebuild), and allows a single connection to the server to be maintained, massively improving tile loading speeds. Also see httpClient's documentation.

  • Properties that use objects without a useful equality and hash code should always be defined once outside of the build method so that their identity (by identical) is not changed - for example, httpClient, tileLoadingInterceptor, errorHandler, and urlTransformer. All properties comprise part of the hashCode & operator ==, which are used to form the Flutter session ImageCache key in the internal image provider (alongside the tile coordinates). This key should not change for a tile unless the configuration is actually changed meaningfully, as this will disrupt the session cache, and mean tiles may need to be fetched unnecessarily.

See the online documentation for an example of the recommended usage.

Annotations

Constructors

FMTCTileProvider.new({required Map<String, BrowseStoreStrategy?> stores, BrowseStoreStrategy? otherStoresStrategy, BrowseLoadingStrategy loadingStrategy = BrowseLoadingStrategy.cacheFirst, bool useOtherStoresAsFallbackOnly = false, bool recordHitsAndMisses = true, Duration cachedValidDuration = Duration.zero, UrlTransformer? urlTransformer, BrowsingExceptionHandler? errorHandler, ValueNotifier<TileLoadingInterceptorMap>? tileLoadingInterceptor, Client? httpClient, @visibleForTesting bool fakeNetworkDisconnect = false, Map<String, String>? headers})
Create an FMTCTileProvider that interacts with a subset of all available stores
FMTCTileProvider.allStores({required BrowseStoreStrategy allStoresStrategy, BrowseLoadingStrategy loadingStrategy = BrowseLoadingStrategy.cacheFirst, bool recordHitsAndMisses = true, Duration cachedValidDuration = Duration.zero, UrlTransformer? urlTransformer, BrowsingExceptionHandler? errorHandler, ValueNotifier<TileLoadingInterceptorMap>? tileLoadingInterceptor, Client? httpClient, @visibleForTesting bool fakeNetworkDisconnect = false, Map<String, String>? headers})
Create an FMTCTileProvider that interacts with all available stores, using one BrowseStoreStrategy efficiently

Properties

cachedValidDuration Duration
The duration for which a tile does not require updating when cached, after which it is marked as expired and updated at the next possible opportunity
final
errorHandler BrowsingExceptionHandler?
A custom callback that will be called when an FMTCBrowsingError is thrown
final
fakeNetworkDisconnect bool
Whether to fake a network disconnect for the purpose of testing
final
hashCode int
The hash code for this object.
no setteroverride
headers Map<String, String>
Custom HTTP headers that may be sent with each tile request
finalinherited
httpClient → Client
Client (such as a IOClient) used to make all network requests
final
loadingStrategy BrowseLoadingStrategy
Determines whether the network or cache is preferred during browse caching, and how to fallback
final
otherStoresStrategy BrowseStoreStrategy?
The behaviour of all other stores not specified in stores
final
recordHitsAndMisses bool
Whether to record the StoreStats.hits and StoreStats.misses statistics
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
stores Map<String, BrowseStoreStrategy?>
The store names from which to (possibly) read/update/create tiles from/in
final
supportsCancelLoading bool
Indicates to flutter_map internals whether to call getImage (when false) or getImageWithCancelLoadingSupport
no setterinherited
tileLoadingInterceptor ValueNotifier<TileLoadingInterceptorMap>?
Allows tracking (eg. for debugging and logging) of the internal tile loading mechanisms
final
urlTransformer UrlTransformer?
Method used to create a tile's storage-suitable UID from it's real URL
final
useOtherStoresAsFallbackOnly bool
Whether to only use tiles retrieved by FMTCTileProvider.otherStoresStrategy after all specified stores have been exhausted (where the tile was not present)
final

Methods

dispose() Future<void>
Called when the TileLayer is disposed
generateReplacementMap(String urlTemplate, TileCoordinates coordinates, TileLayer options) Map<String, String>
Generate the Map of placeholders to replacements, to be used in populateTemplatePlaceholders
inherited
getImage(TileCoordinates coordinates, TileLayer options) ImageProvider<Object>
Retrieve a tile as an image, based on its coordinates and the TileLayer
getImageWithCancelLoadingSupport(TileCoordinates coordinates, TileLayer options, Future<void> cancelLoading) ImageProvider<Object>
Retrieve a tile as an image, based on its coordinates and the TileLayer
inherited
getTileFallbackUrl(TileCoordinates coordinates, TileLayer options) String?
Generate a fallback URL for a tile, based on its coordinates and the TileLayer
inherited
getTileUrl(TileCoordinates coordinates, TileLayer options) String
Generate a primary URL for a tile, based on its coordinates and the TileLayer
inherited
isTileCached({required TileCoordinates coords, required TileLayer options}) Future<bool>
Check whether a specified tile is cached in any of the current stores
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
populateTemplatePlaceholders(String urlTemplate, TileCoordinates coordinates, TileLayer options) String
Replaces placeholders in the form templatePlaceholderElement with their corresponding values
inherited
provideTile({required TileCoordinates coords, required TileLayer options, Object? key, void startedLoading()?, void finishedLoadingBytes()?, bool requireValidImage = false}) Future<Uint8List>
Use FMTC's caching logic to get the bytes of the specific tile (at coords) with the specified TileLayer options and FMTCTileProvider provider
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
override

Static Methods

urlTransformerOmitKeyValues({required String url, required Iterable<String> keys, String link = '=', String delimiter = '&'}) String
Removes key-value pairs from the specified url, given only the keys