1

I am trying to display a random Flutter map using the flutter_maps package. When I was creating this, I couldn't find the 'layers' option under the map options. If I type layers I got an error "Parameter named 'layers' is not defined."

I have added all the required dependencies. How to solve this?

Code:

import 'package:flutter/material.dart';
import 'package:flutter_map/flutter_map.dart';
import 'package:latlong2/latlong.dart' as LatLng;
Container(                         //container 1
          height: 800,
          width: double.infinity,
          child: FlutterMap(
            options: MapOptions(
              center: LatLng.LatLng(23.77176, 90.399452),
              zoom: 8,
            ),
            ),
        ),
Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
Divya
  • 129
  • 8

1 Answers1

1

The layers option is not available in the MapOptions class of the flutter_map package. Instead, you can add one or more layers to the map using the children property of the FlutterMap widget:

return FlutterMap(
    options: MapOptions(
        center: LatLng(51.509364, -0.128928),
        zoom: 9.2,
    ),
    nonRotatedChildren: [
        AttributionWidget.defaultWidget(
            source: 'OpenStreetMap contributors',
            onSourceTapped: null,
        ),
    ],
    children: [
        TileLayer(
            urlTemplate: 'https://tile.openstreetmap.org/{z}/{x}/{y}.png',
            userAgentPackageName: 'com.example.app',
        ),
    ],
);
Matic
  • 393
  • 3
  • 12
  • Thanks for your response. Tried using layers after options. But I couldn't use layers[], if I type layers I get the below error "The named parameter 'layers' isn't defined." Do I need additional permission to use the layer option? – Divya Apr 07 '23 at 11:46
  • @Divya I have updated the code in my answer. Try this way and let me know if it works! – Matic Apr 07 '23 at 11:54
  • Wow! Thanks, it works. May I know why the layer option is not working for me? – Divya Apr 07 '23 at 12:32
  • @Divya I'm glad that it works! About the layer option, I don't know exactly. But I suspect the plugin author has removed the layer option in one of the recent versions. – Matic Apr 07 '23 at 12:43