错误:命名参数“child”是必需的,但没有相应的参数。尝试添加所需的参数

问题描述 投票:0回答:1

这是下面的代码:

`// Automatic FlutterFlow imports
import '/flutter_flow/flutter_flow_theme.dart';
import '/flutter_flow/flutter_flow_util.dart';
import '/custom_code/widgets/index.dart'; // Imports other custom widgets
import '/flutter_flow/custom_functions.dart'; // Imports custom functions
import 'package:flutter/material.dart';
// Begin custom widget code
// DO NOT REMOVE OR MODIFY THE CODE ABOVE!

import 'package:flutter_map/flutter_map.dart';
import 'package:latlong2/latlong.dart' as ll;

class DynamicMap extends StatefulWidget {
  const DynamicMap({
    super.key,
    this.width,
    this.height,
    this.points,
    required this.accessToken,
    required this.startingPoint,
    required this.startingZoom,
  });

  final double? width;
  final double? height;
  final List<LatLng>? points;
  final String accessToken;
  final LatLng startingPoint;
  final double startingZoom;

  @override
  State<DynamicMap> createState() => _DynamicMapState();
}

class _DynamicMapState extends State<DynamicMap> {
  List<Marker> allMarkers = [];

  @override
  void initState() {
    super.initState();
    addMarkersToMap(widget.points);
  }

  void addMarkersToMap(List<LatLng>? points) {
    for (LatLng point in points!) {
      allMarkers.add(
        Marker(
          point: ll.LatLng(point.latitude, point.longitude),
          height: 12,
          width: 12,
          builder: (BuildContext ctx) => Icon(
            Icons.location_pin,
            color: Colors.red,
          ),
        ),
      );
    }
  }

  @override
  Widget build(BuildContext context) {
    return FlutterMap(
      options: MapOptions(
        center: ll.LatLng(
            widget.startingPoint.latitude, widget.startingPoint.longitude),
        zoom: widget.startingZoom,
      ),
      children: [
        TileLayer(
          urlTemplate:
              'https://api.mapbox.com/styles/v1/abdulsgilal579/clv6gzc4k007801o081vja3q9/tiles/256/{z}/{x}/{y}@2x?access_token=${widget.accessToken}',
        ),
        MarkerLayer(
          markers: allMarkers,
        ),
      ],
    );
  }
}`

我收到这两个错误:

错误1:未定义命名参数“builder”。尝试将名称更正为现有命名参数的名称,或使用名称“builder”定义命名参数。

错误2:命名参数“child”是必需的,但没有相应的参数。尝试添加所需的参数。

第 46 行,第 9 个字符

我尝试使用 CHATGPT 解决问题,但没有任何反应。

flutter compilation builder flutterflow
1个回答
0
投票

而不是

      builder: (BuildContext ctx) => Icon(
        Icons.location_pin,
        color: Colors.red,
      ),

你需要

      child: Icon(
        Icons.location_pin,
        color: Colors.red,
      ),

这是 flutter_map 6.0.0 版本中引入的更改,您可以在此处看到https://pub.dev/packages/flutter_map/changelog。如果您使用旧版本,您可以使用代码中现在的构建器

© www.soinside.com 2019 - 2024. All rights reserved.