在 Flutter 上使用 Openstreetmaps 时出错

Error when using Openstreetmaps on Flutter

提问人:Asa Marsal 提问时间:10/26/2023 最后编辑:scaiAsa Marsal 更新时间:10/26/2023 访问量:53

问:

如何修复此错误?

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({

我的代码 :

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

如何修复错误?

flutter flutter-依赖 openstreetmap fluttermap

评论


答:

1赞 Dhafin Rayhan 10/26/2023 #1

在版本中,你应该像这样在它的子项中放一个:flutter_map6.0.0TileLayer

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

所以基本上,更改为 并更改为 .layerschildrenTileLayerOptionsTileLayer