user26507103
user26507103

Reputation: 9

Hi , I'm having an error with MarkerLayer with flutter

When i try to display a showdialog inside another widget i get a The named parameter 'builder' isn't defined. Try correcting the name to an existing named parameter's name, or defining a named parameter with the name 'builder'.dartundefined_named_parameter error

import 'dart:ffi';

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

void main() => runApp(const MyApp());

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: form(),
    );
  }
}


class form extends StatefulWidget {
  @override
  _formstate createState() => _formstate();
}

class _formstate extends State<form>{
 String _nombre = '';
 String _apellido = '';
 TextEditingController _longitudController = TextEditingController();
 TextEditingController _latitudController = TextEditingController();

 @override
Widget build(BuildContext context) {
  return Scaffold(
    appBar: AppBar(
      title: Text('Formulario'),
    ),
    body: Padding(
      padding: EdgeInsets.all(16.0),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.stretch,
        children: [
          TextField(
            onChanged: (value) {
              setState(() {
                _nombre = value;
              });
            },
            decoration: InputDecoration(labelText: 'Nombre'),
          ),
          TextField(
            onChanged: (value) {
              setState(() {
                _apellido = value;
              });
            },
            decoration: InputDecoration(labelText: 'Apellido'),
          ),
          SizedBox(height: 20),
          TextField(
            controller: _latitudController,
            decoration: InputDecoration(labelText: 'Latitud'),
            keyboardType: TextInputType.number,
          ),
          TextField(
            controller: _longitudController,
            decoration: InputDecoration(labelText: 'Longitud'),
            keyboardType: TextInputType.number,
          ),
          SizedBox(height: 20),
          ElevatedButton(
            onPressed: () {
              double latitud = double.tryParse(_latitudController.text) ?? 0.0;
              double longitud = double.tryParse(_longitudController.text) ?? 0.0;

              Navigator.push(
                context,
                MaterialPageRoute(
                  builder: (context) => MapScreen(
                    nombre: _nombre,
                    apellido: _apellido,
                    latitud: latitud,
                    longitud: longitud,
                  ),
                ),
              );
            },
            child: Text('Ir al mapa'),
          ),
        ],
      ),
    ),
  );
}


}



class MapScreen extends StatelessWidget {
  final String nombre;
  final String apellido;
  final double latitud;
  final double longitud;

  MapScreen({
    required this.nombre,
    required this.apellido,
    required this.latitud,
    required this.longitud,
  });

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('El mapa'),
      ),
      body: FlutterMap(
        options: MapOptions(
          initialCenter: LatLng(latitud, longitud),
          initialZoom: 13.0,
        ),
        children: [
 
          TileLayer(
            urlTemplate: "https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png",
            subdomains: ['a', 'b', 'c'],
          ),
          MarkerLayer(
            markers: [
              Marker(
                width: 40.0,
                height: 40.0,
                point: LatLng(latitud, longitud),
                builder: (ctx) => GestureDetector(
                  onTap: () {
                    showDialog(
                      context: context,
                      builder: (BuildContext context) {
                        return AlertDialog(
                          title: Text('Info acerca de la ubicación'),
                          content: Column(
                            crossAxisAlignment: CrossAxisAlignment.start,
                            children: [
                              Text('Nombre: $nombre'),
                              Text('Apellido: $apellido'),
                              Text('Ubicación: ${latitud.toString()}, ${longitud.toString()}'),
                            ],
                          ),
                          actions: [
                            TextButton(
                              onPressed: () {
                                Navigator.of(context).pop();
                              },
                              child: Text('Cerrar'),
                            ),
                          ],
                        );
                      },
                    );
                  },
                  
                ),
                child: Icon(
                    Icons.location_pin,
                    size: 40.0,
                    color: Colors.red,
                  ),
              ),
            ],
          ),
        ],
        
       
      ),
    );
  }
}

I tried changing the context and the position of the builder but this just doesn't work

Upvotes: -1

Views: 43

Answers (1)

JaffaKetchup
JaffaKetchup

Reputation: 1638

flutter_map Marker's no longer support builders, they instead now take children. This has been done as there was no significant advantage internally to using the builder pattern, and the child pattern is more widely used.

Please see https://github.com/fleaflet/flutter_map/blob/master/CHANGELOG.md#600---20231009 & https://github.com/fleaflet/flutter_map/pull/1659 for more info.

Upvotes: 0

Related Questions