Donovan
Donovan

Reputation: 11

The named parameters arent definded

I'm trying to develop a simple application where you can you to anonymously see where friended users are on a realistic map.

These are the three errors I get:

  1. The named parameter 'layers' isn't defined. Try correcting the name to an existing named parameter's name, or defining a named parameter with the name 'layers'.dartundefined_named_parameter

  2. The method 'TileLayerOptions' isn't defined for the type '_HotSpotState'. Try correcting the name to the name of an existing method, or defining a method named 'TileLayerOptions'.dartundefined_method

  3. The method 'MarkerLayerOptions' isn't defined for the type '_HotSpotState'. Try correcting the name to the name of an existing method, or defining a method named 'MarkerLayerOptions'.dartundefined_method

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);
}

Upvotes: 1

Views: 2605

Answers (1)

Adeel Nazim
Adeel Nazim

Reputation: 724

Change your TileLayerOptions to TileLayer and MarkerLayerOptions to MarkerLayer. check the official flutter_map example here https://github.com/fleaflet/flutter_map

Upvotes: 4

Related Questions