-2

How to fix this error?

Error : lib/pages/osmmapstest.dart:17:9: Error: No named parameter with the name 'layers'.
        layers: [
/C:/Users/HP/AppData/Local/Pub/Cache/hosted/pub.dev/flutter_map-6.0.0/lib/src/map/widget.dart:29:9: Context: Found this candidate, but the arguments don't match.
  const FlutterMap({

My Code :

import 'package:flutter/material.dart';
import 'package:flutter_map/flutter_map.dart';
import 'package:latlong2/latlong.dart';

class MapPage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('OpenStreetMaps'),
      ),
      body: FlutterMap(
        options: MapOptions(
          center: LatLng(51.5, -0.09),
          zoom: 13.0,
        ),
        layers: [
          TileLayerOptions(
            urlTemplate:
                'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
            subdomains: ['a', 'b', 'c'],
          ),
        ],
      ),
    );
  }
}
Pubspec.yaml
flutter_map: ^6.0.0
latlong2: ^0.9.0

How to fix the error?

1 Answer 1

1

In flutter_map version 6.0.0, you should put a TileLayer inside its children like this:

FlutterMap(
  // ...
  children: [
    TileLayer(
      urlTemplate:
          'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
      subdomains: ['a', 'b', 'c'],
    ),
  ],
)

So basically, change layers to children and change TileLayerOptions to TileLayer.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.