Creating a new map layer is just as easy as it is to create a normal StatelessWidget
or StatefulWidget
.
Only one method call is needed to 'connect' the widget to the map state: FlutterMapState.maybeOf()
. This call does two important things:
Cause the widget/layer to rebuild automatically when required (if in the build
method)
Expose the map's internal state, meaning that it's information (such as zoom) can be accessed
You can see an example of how this is done below:
Attempting to use the widget above outside of a FlutterMap
widget will result in an error, due to the usage of FlutterMapState.of(context)
.
If creating a hybrid widget for usage outside of a layer, use the maybeOf
method instead.
One common requirement is a custom TileProvider
, and potentially a custom ImageProvider
inside. This will allow your plugin to intercept all tile requests made by a map, and take your own action(s), before finally returning a tile.
Some useful steps are below, but there are more properties of a TileProvider
that can be overridden.
TileProvider
To create your own usable TileProvider
, the first step is making a class that extends
the abstract class. It is not recommended to implement
the base, as this will require overriding methods unnecessarily for most custom providers.
getImage
The majority of custom TileProviders
will want to implement their own method to retrieve tiles. This is done by overriding the getImage
method, and usually specifying your own ImageProvider
, for example:
Notice that the 'User-Agent' header has been changed. This is recommended, as it helps further differentiate your plugin's traffic from vanilla 'flutter_map' traffic.
getTileUrl
Some custom TileProviders
may want to change the way URLs for tiles are generated. Note that this is quite advanced usage.
There are many independently maintained plugins created by the 'flutter_map' community that give extra, prebuilt functionality, saving you even more time and potentially money.
Unfortunately, you may need more niche functionality that hasn't been provided by an existing plugin or by 'flutter_map' itself. Alternatively, you may have found a gap in functionality that not everyone will need, but some people will: in this case, it's likely the maintainers will ask you to submit a plugin instead of a pull request.
Plugins can add/change a wide variety of functionality, so this guide is not exhaustive. However, it will help with the most common requirements. Each subpage covers a specific part of the plugin API, and the section below sets out requirements for plugins to be accepted into the list.
If you've made your own plugin that you're willing to share, you can add it to this list by creating a pull request in GitHub. We're always looking forward to see what you've made!
When submitting a plugin & PR, please ensure the plugin:
preferably includes 'flutter_map_' in the name
preferably available via a pub.dev installation
includes a runnable example, and/or screenshots or recordings
has a description that accurately and concisely represents your plugin
If you want to provide extra assistance to your users in a shared space, consider the official 'flutter_map' Discord server! Join using the link at the bottom of this page, and ping '@Github Maintainer' to be added to the 'Plugin Owner' role. You can then be easily identified and provide help or announcements in a dedicated plugins channel.