Title features in Flutter maps

This section helps to learn about how to add title in the maps and customize them.

Title text

You can define the maps title using SfMaps.title property. You can set the text for the title using the MapsTitle.text property.

@override
Widget build(BuildContext context) {
  return Scaffold(
     body: Center(
       child: Container(
         height: 350,
         child: Padding(
           padding: EdgeInsets.only(left: 15, right: 15),
           child: SfMaps(
             title: MapTitle(
               text: 'World Map',
             ),
             layers: [
               MapShapeLayer(
                 delegate: MapShapeLayerDelegate(
                   shapeFile: "assets/world_map.json",
                   shapeDataField: "continent",
                 ),
               ),
             ],
           ),
         ),
       ),
     )
   );
}

Maps title support

Text style

You can change the style of the title text in the maps using the MapsTitle.textStyle property.

@override
Widget build(BuildContext context) {
  return Scaffold(
    body: Center(
      child: Container(
        height: 350,
        child: Padding(
          padding: EdgeInsets.only(left: 15, right: 15),
          child: SfMaps(
            title: MapTitle(
              text: 'World Map',
              textStyle: const TextStyle(
                  color: Colors.red,
                  fontSize: 16,
                  fontWeight: FontWeight.bold,
                  fontStyle: FontStyle.italic,
                  fontFamily: 'Times'
              ),
            ),
            layers: [
              MapShapeLayer(
                delegate: MapShapeLayerDelegate(
                  shapeFile: "assets/world_map.json",
                  shapeDataField: "continent",
                ),
              ),
            ],
          ),
        ),
      ),
    )
  );
}

Using SfMapsTheme

You can also change the style of the title text in the maps using the SfMapsThemeData.titleTextStyle property.

NOTE

You must import the theme.dart library from the Core package to use SfMapsTheme.

@override
Widget build(BuildContext context) {
  return Scaffold(
      body: Center(
        child: Container(
          height: 350,
          child: Padding(
            padding: EdgeInsets.only(left: 15, right: 15),
            child: SfMapsTheme(
              data: SfMapsThemeData(
                titleTextStyle: const TextStyle(
                    color: Colors.red,
                    fontSize: 16,
                    fontWeight: FontWeight.bold,
                    fontStyle: FontStyle.italic,
                    fontFamily: 'Times'
                ),
              ),
              child: SfMaps(
                title: MapTitle(
                  text: 'World Map',
                ),
                layers: [
                  MapShapeLayer(
                    delegate: const MapShapeLayerDelegate(
                      shapeFile: "assets/world_map.json",
                      shapeDataField: "continent",
                    ),
                  ),
                ],
              ),
            ),
          ),
        ),
      ),
   );
}

Maps title textStyle

Text alignment

You can align the title text in the maps using the MapsTitle.alignment property. By default, the alignment will be center. You can also align the text in the available alignment options in Alignment.

@override
Widget build(BuildContext context) {
   return Scaffold(
      body: Center(
        child: Container(
          height: 350,
          child: Padding(
            padding: EdgeInsets.only(left: 15, right: 15),
            child: SfMaps(
              title: MapTitle(
                text: 'World Map',
                textStyle: const TextStyle(
                    color: Colors.red,
                    fontSize: 16,
                    fontWeight: FontWeight.bold,
                    fontStyle: FontStyle.italic,
                    fontFamily: 'Times'
                ),
                alignment: Alignment.centerLeft,
              ),
              layers: [
                MapShapeLayer(
                  delegate: MapShapeLayerDelegate(
                    shapeFile: "assets/world_map.json",
                    shapeDataField: "continent",
                  ),
                ),
              ],
            ),
          ),
        ),
      ),
   );
}

Maps title alignment

Background color

You can change the background color of the title in the maps using the MapsTitle.color.

@override
Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: Container(
          height: 350,
          child: Padding(
            padding: EdgeInsets.only(left: 15, right: 15),
            child: SfMaps(
              title: MapTitle(
                text: 'World Map',
                textStyle: const TextStyle(
                    color: Colors.red,
                    fontSize: 16,
                    fontWeight: FontWeight.bold,
                    fontStyle: FontStyle.italic,
                    fontFamily: 'Times'
                ),
                color: Colors.lightBlueAccent,
              ),
              layers: [
                MapShapeLayer(
                  delegate: MapShapeLayerDelegate(
                    shapeFile: "assets/world_map.json",
                    shapeDataField: "continent",
                  ),
                ),
              ],
            ),
          ),
        ),
      ),
   );
}

Maps title background color

Decoration

You can decorate the title of maps using the MapsTitle.decoration property. You can use BoxDecoration, ShapeDecoration or create a custom Decoration.

@override
Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: Container(
          height: 350,
          child: Padding(
            padding: EdgeInsets.only(left: 15, right: 15),
            child: SfMaps(
              title: MapTitle(
                text: 'World Map',
                textStyle: const TextStyle(
                    color: Colors.red,
                    fontSize: 16,
                    fontWeight: FontWeight.bold,
                    fontStyle: FontStyle.italic,
                    fontFamily: 'Times'
                ),
                decoration: BoxDecoration(
                  color: Colors.lightBlueAccent,
                  border: Border.all(color: Colors.red, width: 2),
                  borderRadius: const BorderRadius.all(Radius.circular(4)),
                  shape: BoxShape.rectangle,
                ),
              ),
              layers: [
                MapShapeLayer(
                  delegate: MapShapeLayerDelegate(
                    shapeFile: "assets/world_map.json",
                    shapeDataField: "continent",
                  ),
                ),
              ],
            ),
          ),
        ),
      ),
   );
}

Maps title decoration

Margin

You can add margin to the maps title using the MapsTitle.margin property.

@override
Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: Container(
          height: 350,
          child: Padding(
            padding: EdgeInsets.only(left: 15, right: 15),
            child: SfMaps(
              title: MapTitle(
                text: 'World Map',
                textStyle: const TextStyle(
                    color: Colors.red,
                    fontSize: 16,
                    fontWeight: FontWeight.bold,
                    fontStyle: FontStyle.italic,
                    fontFamily: 'Times'
                ),
                margin: const EdgeInsets.only(top: 50),
                decoration: BoxDecoration(
                  color: Colors.lightBlueAccent,
                  border: Border.all(color: Colors.red, width: 2),
                  borderRadius: const BorderRadius.all(Radius.circular(4)),
                  shape: BoxShape.rectangle,
                ),
              ),
              layers: [
                MapShapeLayer(
                  delegate: MapShapeLayerDelegate(
                    shapeFile: "assets/world_map.json",
                    shapeDataField: "continent",
                  ),
                ),
              ],
            ),
          ),
        ),
      ),
   );
}

Maps title margin support

Padding

You can add padding to the maps title using the MapsTitle.padding property.

@override
Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: Container(
          height: 350,
          child: Padding(
            padding: EdgeInsets.only(left: 15, right: 15),
            child: SfMaps(
              title: MapTitle(
                text: 'World Map',
                textStyle: const TextStyle(
                    color: Colors.red,
                    fontSize: 16,
                    fontWeight: FontWeight.bold,
                    fontStyle: FontStyle.italic,
                    fontFamily: 'Times'
                ),
                margin: const EdgeInsets.all(10),
                padding: const EdgeInsets.all(10),
                decoration: BoxDecoration(
                  color: Colors.lightBlueAccent,
                  border: Border.all(color: Colors.red, width: 2),
                  borderRadius: const BorderRadius.all(Radius.circular(4)),
                  shape: BoxShape.rectangle,
                ),
              ),
              layers: [
                MapShapeLayer(
                  delegate: MapShapeLayerDelegate(
                    shapeFile: "assets/world_map.json",
                    shapeDataField: "continent",
                  ),
                ),
              ],
            ),
          ),
        ),
      ),
   );
}

Maps title padding support