未定义命名参数



我正在尝试开发一个简单的应用程序,您可以匿名查看好友用户在现实地图上的位置。

这是我得到的三个错误:

  1. 未定义命名参数"layers"。尝试将名称更正为现有的命名参数的名称,或者定义一个名为"layers"的命名参数。

  2. 方法'TileLayerOptions'没有为类型'_HotSpotState'定义。尝试将名称更正为现有方法的名称,或者定义一个名为"TileLayerOptions"的方法。

  3. 方法'MarkerLayerOptions'没有为类型'_HotSpotState'定义。尝试将名称更正为现有方法的名称,或者定义一个名为"MarkerLayerOptions"的方法。

import 'package:flutter/material.dart';
import 'package:flutter_map/flutter_map.dart';
import 'package:latlong2/latlong.dart';
import 'dart:math';
class HotSpot extends StatefulWidget {
@override
_HotSpotState createState() => _HotSpotState();
}
class _HotSpotState extends State<HotSpot> {
List<User> users = [];
MapController mapController = MapController();
Random random = Random();
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('HotSpot'),
),
body: FlutterMap(
options: MapOptions(
center: LatLng(0, 0),
zoom: 5.0,
),
layers: [
TileLayerOptions(
urlTemplate: 'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
subdomains: ['a', 'b', 'c'],
),
MarkerLayerOptions(
markers: users
.map((user) => Marker(
point: LatLng(user.latitude, user.longitude),
builder: (context) => Container(
child: Icon(
Icons.location_on,
color: Colors.red,
),
),
))
.toList(),
),
],
mapController: mapController,
),
floatingActionButton: FloatingActionButton(
onPressed: () {
// add a random user to the map
double latitude = random.nextDouble() * 180 - 90;
double longitude = random.nextDouble() * 360 - 180;
User user = User(latitude, longitude);
setState(() {
users.add(user);
});
},
child: Icon(Icons.add),
),
);
}
}
class User {
double latitude;
double longitude;
User(this.latitude, this.longitude);
}

更改TileLayerOptionsTileLayerMarkerLayerOptionsMarkerLayer.查看官方的flutter_map示例https://github.com/fleaflet/flutter_map

最新更新