Flutter-导航器将推入infoWindowText内部

时间:2019-02-20 15:56:21

标签: google-maps flutter

我有这样的东西

@Override
public WebResourceResponse (WebView view, WebResourceRequest request) {
    Log.i("shouldInterceptRequest", "method:" + request.method)
}

我需要在信息窗口文本中创建一个“导航推送”(例如href)。有人知道什么是正确的方法吗?

---更新---

我在这里https://github.com/flutter/flutter/issues/24864阅读了一种将id设置为marker的方法。我尝试此代码,但返回

  

在“标记”类中没有名为“ id”的setter。

 void onMapCreated(GoogleMapController controller) {
  setState(() {
    mapController = controller;
    for (int i = 0; i < list.length; i++) {
      var corte = list[0].keys.elementAt(i).split('/');
      list.forEach((coords) {
        mapController.addMarker(MarkerOptions(
            position: LatLng(coords.values.elementAt(i).latitude,
                coords.values.elementAt(i).longitude),
            icon: BitmapDescriptor.defaultMarkerWithHue(corte[1] == "tipo:0"
                ? BitmapDescriptor.hueRed
                : corte[1] == "tipo:4"
                    ? BitmapDescriptor.hueBlue
                    : corte[1] == "tipo:3"
                        ? BitmapDescriptor.hueGreen
                        : corte[1] == "tipo:2"
                            ? BitmapDescriptor.hueYellow
                            : null),
            infoWindowText: InfoWindowText(corte[0], 'Ver')));
      });
    }
  });
}

1 个答案:

答案 0 :(得分:1)

在州一级创建Map变量:

Map<String,String> markerMap;

并修改您的方法:

        void onMapCreated(GoogleMapController controller) async {
              setState(() {
                mapController = controller;

                markerMap = Map();

                for (int i = 0; i < list.length; i++) {
                    var corte = list[0].keys.elementAt(i).split('/');   
                    Marker marker = await mapController.addMarker(MarkerOptions(
                    position: LatLng(list[0].values.elementAt(i).latitude, list[0].values.elementAt(i).longitude),
                    icon: BitmapDescriptor.defaultMarkerWithHue(
                          corte[1] == "tipo:0"
                        ? BitmapDescriptor.hueRed
                        : corte[1] == "tipo:4"
                        ? BitmapDescriptor.hueBlue
                        : corte[1] == "tipo:3"
                        ? BitmapDescriptor.hueGreen
                        : corte[1] == "tipo:2"
                        ? BitmapDescriptor.hueYellow
                        : null),
                    infoWindowText: InfoWindowText(corte[0], 'Ver')));

                    markerMap[marker.id] = corte[2];



                    mapController.onInfoWindowTapped.add((marker) {

                    final corte2 = markerMap[marker.id];

                    Navigator.push(
                        context,
                        new MaterialPageRoute(
                        builder: (context) => corte[1] == "tipo:0"          
                          ? new MeterDetailsChartPage(
                              elemento: metersDetails[int.parse(corte2)],
                              estate: this.estate,
                              parcela: widget.parcela)
                          : corte[1] == "tipo:4"
                              ? new ValvePage(
                                  elemento: valvesDetails[int.parse(corte2)],
                                  estate: this.estate,
                                  parcela: widget.parcela)
                          : corte[1] == "tipo:3"
                              ? new RelePage(
                                  elemento: relesDetails[int.parse(corte2)],
                                  estate: this.estate,
                                  parcela: widget.parcela)
                          : corte[1] == "tipo:2"
                              ? new SensorPage(
                                  elemento: sensorsDetails[int.parse(corte2)],
                                  estate: this.estate,
                                  parcela: widget.parcela)
                            : null)
                        );
                  });
                }
              });
            }

);