Error when using Openstreetmaps on Flutter

140 views Asked by At

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

There are 1 answers

0
Dhafin Rayhan On BEST ANSWER

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.