flutter_map Docs
Project Links💝 Support Us
v3
v3
  • flutter_map
  • Getting Started
    • Installation
    • Additional Setup
    • Examples
    • How Does It Work?
      • Raster vs Vector Tiles
  • Usage
    • Base Widget
    • Options
      • Recommended Options
      • Other Options
    • Layers
      • Tile Layer
        • Recommended Options
        • Tile Providers
        • Other Options
      • Marker Layer
      • Polygon Layer
      • Polyline Layer
      • Circle Layer
      • Attribution Layer
      • WMS Usage
    • Controller
    • Full API Reference
  • Plugins
    • Plugins List
    • Making A Plugin
      • Creating New Tile Providers
      • Creating New Layers
  • Tile Servers
    • Using Mapbox
    • Using Stadia Maps
    • Using Thunderforest
    • Offline Mapping
    • Other Options
  • FAQs
    • Frequently Asked Questions
    • Map Controller Issues
  • Migration
    • To v3.0.0
    • To v2.0.0
    • Older Versions
      • To v1.1.0
      • To v1.0.0
      • To v0.15.0
  • Contributing
  • Credits
Powered by GitBook

© flutter_map Authors & Maintainers

On this page

Was this helpful?

Export as PDF
  1. Plugins
  2. Making A Plugin

Creating New Layers

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:

class CustomLayer extends StatelessWidget {
  const CustomLayer({super.key});

  @override
  Widget build(BuildContext context) {
    final mapState = FlutterMapState.maybeOf(context)!;
    // Use `mapState` as necessary, for example `mapState.zoom`
  }
}

Attempting to use the widget above outside of a FlutterMap widget will result in an error.

The FlutterMapState.maybeOf method will return null, because it cannot locate a parent/inherited state, and therefore cause a null exception.

PreviousCreating New Tile ProvidersNextUsing Mapbox

Last updated 2 years ago

Was this helpful?