Flutter 错误:类型为';PolylineResult';用于';对于';循环必须实现';Iterable<;动态>';

Flutter 错误:类型为';PolylineResult';用于';对于';循环必须实现';Iterable<;动态>';,flutter,google-maps,dart,Flutter,Google Maps,Dart,我正在尝试创建一个谷歌地图,并在两个坐标之间绘制一条多段线。但是我得到了下面给出的错误1。 我试了一下建议的修复方法 即用result.values替换result。在这种情况下,我得到错误2 有人能告诉我为什么这是一个问题(为什么修复不起作用)?另外,如果您能为这个问题提出解决方案,我将不胜感激 错误1: Error: The type 'PolylineResult' used in the 'for' loop must implement 'Iterable<dynamic>

我正在尝试创建一个谷歌地图,并在两个坐标之间绘制一条多段线。但是我得到了下面给出的错误1。 我试了一下建议的修复方法

即用
result.values
替换
result
。在这种情况下,我得到错误2

有人能告诉我为什么这是一个问题(为什么修复不起作用)?另外,如果您能为这个问题提出解决方案,我将不胜感激

错误1:

Error: The type 'PolylineResult' used in the 'for' loop must implement 'Iterable<dynamic>'.
     - 'PolylineResult' is from 'package:flutter_polyline_points/src/utils/polyline_result.dart' ('../../../flutter/.pub-cache/hosted/pub.dartlang.org/flutter_polyline_points-0.2.4/lib/src/utils/polyline_result.dart').
     - 'Iterable' is from 'dart:core'.
          for (PointLatLng point in result) {
代码:

void main()=>
runApp(MaterialApp(debugShowCheckedModeBanner:false,home:MapPage());
const双摄像机_变焦=13;
const双摄像头倾斜=0;
常数双摄像机_轴承=30;
const LatLng SOURCE_LOCATION=LatLng(42.7477863,-71.1699932);
施工图目的地位置=施工图(42.6871386,-71.2143403);
const PointLatLng POINT_SOURCE_LOCATION=PointLatLng(42.7477863,-71.1699932);
常数点位=点位(42.6871386,-71.2143403);
类MapPage扩展StatefulWidget{
@凌驾
State createState()=>MapPageState();
}
类MapPageState扩展了状态{
Completer _controller=Completer();
设置_标记={};
集合_polylines={};
列出多段线坐标=[];
多段线点多段线点=多段线点();
字符串googleAPIKey=“”;
位图描述符源图标;
位映射描述符定义;
双针孔位置=-100;
PinInformation currentlySelectedPin=PinInformation(
pinPath:“”,
化身路径:“”,
位置:LatLng(0,0),
位置名称:“”,
标签颜色:颜色。灰色);
pininfo信息源pininfo;
PinInformation destinationPinInfo;
@凌驾
void initState(){
super.initState();
设置来源和目的();
}
void setMapPins(){
//源引脚
_标记。添加(标记)(
//此标记id可以是唯一标识每个标记的任何内容。
markerId:markerId('sourcePin'),
位置:源位置,
onTap:(){
设置状态(){
currentlySelectedPin=sourcePinInfo;
pinPillPosition=0;
});
},
图标:sourceIcon);
sourcePinInfo=PinInformation(
locationName:“开始位置”,
位置:源位置,
pinPath:“资产/driving_pin.png”,
头像路径:“资产/友谊1.jpg”,
标签颜色:颜色。蓝色调);
//目的地pin码
_标记。添加(标记)(
//此标记id可以是唯一标识每个标记的任何内容。
markerId:markerId('destPin'),
位置:目的地位置,
onTap:(){
设置状态(){
currentlySelectedPin=destinationPinInfo;
pinPillPosition=0;
});
},
图标:Destinationion);
destinationPinInfo=PinInformation(
locationName:“结束位置”,
地点:目的地地点,
pinPath:“资产/目的地\地图\标记.png”,
化身路径:“资产/友谊2.jpg”,
标签颜色:颜色。紫色);
}
void setSourceAndDestinations()异步{
sourceIcon=等待BitmapDescriptor.fromAssetImage(
ImageConfiguration(devicePixelRatio:2.5),“资产/驱动_pin.png”);
DestinationOn=等待BitmapDescriptor.fromAssetImage(
图像配置(devicePixelRatio:2.5),
“assets/destination_map_marker.png”);
}
创建时无效(GoogleMapController){
controller.setMapStyle(Utils.mapStyles);
_控制器。完成(控制器);
setMapPins();
设置多段线();
}
@凌驾
小部件构建(构建上下文){
CameraPosition initialLocation=CameraPosition(
变焦:相机变焦,
轴承:摄像机轴承,
倾斜:摄像机倾斜,
目标:源位置);
返回脚手架(
主体:堆栈(子对象:[
谷歌地图(
myLocationEnabled:对,
同谋:是的,
tiltGesturesEnabled:false,
标记:_标记,
多段线:_多段线,
mapType:mapType.normal,
initialCameraPosition:initialLocation,
onMapCreated:onMapCreated,
onTap:(LatLng位置){
设置状态(){
pinPillPosition=-100;
});
},
),
MapPinpill组件(
pinPillPosition:pinPillPosition,
currentlySelectedPin:currentlySelectedPin)
]));
}
setPolylines()异步{
PolylineResult结果=等待polylinePoints.GetRouteBeween坐标(
Googleapkey,
点源位置,
点目标位置,
);
如果(结果!=null){
用于(点定位结果中的点){
多段线坐标.add(LatLng(点.纬度,点.经度));
}
}
设置状态(){
多段线多段线=多段线(
polylineId:polylineId(“多边形”),
颜色:颜色。来自argb(255,40,122,198),
点:多段线坐标);
_多段线。添加(多段线);
});
}
}
类信息{
字符串路径;
字符串虚拟路径;
定位;
字符串位置名称;
颜色标签颜色;
PinInformation({this.pinPath,this.avatarPath,this.location,this.locationName,this.labelColor});
}

该列表存储在
PolylineResult
字段中。通过
result.points
访问它们

Error: The getter 'values' isn't defined for the class 'PolylineResult'.
     - 'PolylineResult' is from 'package:flutter_polyline_points/src/utils/polyline_result.dart' ('../../../flutter/.pub-cache/hosted/pub.dartlang.org/flutter_polyline_points-0.2.4/lib/src/utils/polyline_result.dart').
    Try correcting the name to the name of an existing getter, or defining a getter or field named 'values'.
          for (PointLatLng point in result.values) {
void main() =>
    runApp(MaterialApp(debugShowCheckedModeBanner: false, home: MapPage()));

const double CAMERA_ZOOM = 13;
const double CAMERA_TILT = 0;
const double CAMERA_BEARING = 30;
const LatLng SOURCE_LOCATION = LatLng(42.7477863, -71.1699932);
const LatLng DEST_LOCATION = LatLng(42.6871386, -71.2143403);

const PointLatLng POINT_SOURCE_LOCATION = PointLatLng(42.7477863, -71.1699932);
const PointLatLng POINT_DEST_LOCATION = PointLatLng(42.6871386, -71.2143403);

class MapPage extends StatefulWidget {
  @override
  State<StatefulWidget> createState() => MapPageState();
}

class MapPageState extends State<MapPage> {
  Completer<GoogleMapController> _controller = Completer();
  Set<Marker> _markers = {};
  Set<Polyline> _polylines = {};
  List<LatLng> polylineCoordinates = [];
  PolylinePoints polylinePoints = PolylinePoints();
  String googleAPIKey = "<YOUR_API_KEY>";
  BitmapDescriptor sourceIcon;
  BitmapDescriptor destinationIcon;
  double pinPillPosition = -100;
  PinInformation currentlySelectedPin = PinInformation(
      pinPath: '',
      avatarPath: '',
      location: LatLng(0, 0),
      locationName: '',
      labelColor: Colors.grey);
  PinInformation sourcePinInfo;
  PinInformation destinationPinInfo;

  @override
  void initState() {
    super.initState();
    setSourceAndDestinationIcons();
  }

  void setMapPins() {
    // source pin
    _markers.add(Marker(

        // This marker id can be anything that uniquely identifies each marker.
        markerId: MarkerId('sourcePin'),
        position: SOURCE_LOCATION,
        onTap: () {
          setState(() {
            currentlySelectedPin = sourcePinInfo;
            pinPillPosition = 0;
          });
        },
        icon: sourceIcon));

    sourcePinInfo = PinInformation(
        locationName: "Start Location",
        location: SOURCE_LOCATION,
        pinPath: "assets/driving_pin.png",
        avatarPath: "assets/friend1.jpg",
        labelColor: Colors.blueAccent);

    // destination pin
    _markers.add(Marker(
        // This marker id can be anything that uniquely identifies each marker.
        markerId: MarkerId('destPin'),
        position: DEST_LOCATION,
        onTap: () {
          setState(() {
            currentlySelectedPin = destinationPinInfo;
            pinPillPosition = 0;
          });
        },
        icon: destinationIcon));

    destinationPinInfo = PinInformation(
        locationName: "End Location",
        location: DEST_LOCATION,
        pinPath: "assets/destination_map_marker.png",
        avatarPath: "assets/friend2.jpg",
        labelColor: Colors.purple);
  }

  void setSourceAndDestinationIcons() async {
    sourceIcon = await BitmapDescriptor.fromAssetImage(
        ImageConfiguration(devicePixelRatio: 2.5), 'assets/driving_pin.png');

    destinationIcon = await BitmapDescriptor.fromAssetImage(
        ImageConfiguration(devicePixelRatio: 2.5),
        'assets/destination_map_marker.png');
  }

  void onMapCreated(GoogleMapController controller) {
    controller.setMapStyle(Utils.mapStyles);
    _controller.complete(controller);

    setMapPins();
    setPolylines();
  }

  @override
  Widget build(BuildContext context) {
    CameraPosition initialLocation = CameraPosition(
        zoom: CAMERA_ZOOM,
        bearing: CAMERA_BEARING,
        tilt: CAMERA_TILT,
        target: SOURCE_LOCATION);

    return Scaffold(
        body: Stack(children: <Widget>[
      GoogleMap(
        myLocationEnabled: true,
        compassEnabled: true,
        tiltGesturesEnabled: false,
        markers: _markers,
        polylines: _polylines,
        mapType: MapType.normal,
        initialCameraPosition: initialLocation,
        onMapCreated: onMapCreated,
        onTap: (LatLng location) {
          setState(() {
            pinPillPosition = -100;
          });
        },
      ),
      MapPinPillComponent(
          pinPillPosition: pinPillPosition,
          currentlySelectedPin: currentlySelectedPin)
    ]));
  }

  setPolylines() async {
    PolylineResult result = await polylinePoints.getRouteBetweenCoordinates(
      googleAPIKey,
      POINT_SOURCE_LOCATION,
      POINT_DEST_LOCATION,
    );

    if (result != null) {
      for (PointLatLng point in result) {
        polylineCoordinates.add(LatLng(point.latitude, point.longitude));
      }
    }

    setState(() {
      Polyline polyline = Polyline(
          polylineId: PolylineId("poly"),
          color: Color.fromARGB(255, 40, 122, 198),
          points: polylineCoordinates);
      _polylines.add(polyline);
    });
  }
}

class PinInformation {
  String pinPath;
  String avatarPath;
  LatLng location;
  String locationName;
  Color labelColor;

  PinInformation({this.pinPath, this.avatarPath, this.location, this.locationName, this.labelColor});
}