在Mapcontroller更新时,Flutter / Dart Google Maps重新渲染小部件

时间:2019-01-15 22:37:25

标签: google-maps dart flutter

如何根据地图控制器所做的更改重新渲染Google Map小部件?

@override
  Widget build(BuildContext context) {
    return GoogleMap(
      onMapCreated: _onMapCreated,
      options: GoogleMapOptions(
        compassEnabled: true,
        cameraPosition: CameraPosition(
          target: LatLng(-36.8446085, 174.7547239),
          zoom: 15.0,
        ),
      ),
    );
  }

该方法通过使用地图控制器添加标记并根据用户的当前位置进行动画缩放来更新。此方法由FAB在此Google地图呈现窗口小部件的父窗口小部件上触发StreamController来运行。

void _populateUserLocation() {
    _getLocation().then((location) {
      setState(() {
        userLocation = LatLng(location['latitude'], location['longitude']);
      });
    });
    _mapController.addMarker(
      MarkerOptions(
        position: userLocation,
        infoWindowText: InfoWindowText("!", "Your are here"),
      )
    );
    _mapController.animateCamera(
      CameraUpdate.newCameraPosition(
        CameraPosition(
          target: userLocation,
          tilt: 50.0,
          zoom: 20.0,
        )
      )
    );
  }

当前,这仅在第二台FAB印刷机上按预期运行。这意味着该地图未根据地图控制器所做的更改适当地重新呈现。

0 个答案:

没有答案