Flutter 如何在子级(使用者)中使用此条件语句

Flutter 如何在子级(使用者)中使用此条件语句,flutter,dart,Flutter,Dart,我无法获得if(绘图)绘图(onDrawEnd:\u onDrawPolygon);由于某种原因要通过的语句。有人知道怎么做吗?请告知 body: Stack(children: <Widget>[ SizedBox( width: MediaQuery.of(context).size.width, // or use fixed size like 200 height: MediaQuery.of(context).size.height,

我无法获得if(绘图)绘图(onDrawEnd:\u onDrawPolygon);由于某种原因要通过的语句。有人知道怎么做吗?请告知

body: Stack(children: <Widget>[
  SizedBox(
    width:
        MediaQuery.of(context).size.width, // or use fixed size like 200
    height: MediaQuery.of(context).size.height,
    child: Consumer<ProviderMaps>(builder: (context, Provmap, widget) {
      return GoogleMap(
          myLocationEnabled: true,
          compassEnabled: true,
          mapToolbarEnabled: true,
          zoomControlsEnabled: true,
          zoomGesturesEnabled: true,
          onLongPress: _addMarkerLongPressed,
          myLocationButtonEnabled: false,
          mapType: maptype,
          onTap: (latLng) {
            _selectCenterCircle(latLng);
          },
          onMapCreated: (GoogleMapController controller) {
            mapController = controller;
            _controller.complete(controller);
            isMapCreated = true;
            changeMapMode();
            subscription.pause();
            changeMapType();
            setState(() {});
          },
          initialCameraPosition:
              CameraPosition(target: LatLng(lat, lng), zoom: 10.0),
          circles: _getCircles(),
          markers: _getMarkers(),
          polygons: _getPolygons()
        (() {
        if (drawing) Draw(onDrawEnd: _onDrawPolygon);
      }()));
    }),
  ),

  Column(children: <Widget>[
    if (enableFreeDraw)
      FloatingActionButton(
body:Stack(子项:[
大小盒子(
宽度:
MediaQuery.of(context).size.width//或使用固定大小,如200
高度:MediaQuery.of(context).size.height,
子:消费者(构建器:(上下文、Provmap、小部件){
返回谷歌地图(
myLocationEnabled:对,
同谋:是的,
mapToolbarEnabled:true,
ZoomControl启用:对,
zoomGesturesEnabled:对,
onLongPress:\u addmarker longpress,
myLocationButtonEnabled:false,
mapType:mapType,
onTap:(拉丁语){
_选择中心圆(板条);
},
onMapCreated:(谷歌地图控制器){
mapController=控制器;
_控制器。完成(控制器);
IsmaCreated=true;
changeMapMode();
subscription.pause();
changeMapType();
setState((){});
},
初始摄像机位置:
摄像机位置(目标:LatLng(lat,lng),缩放:10.0),
圆:_getCircles(),
标记:_getMarkers(),
多边形:_getPolygons()
(() {
如果(绘图)绘制(onDrawEnd:_onDrawPolygon);
}()));
}),
),
栏(儿童:[
如果(启用自由绘图)
浮动操作按钮(
在上面的代码段运行之后,我看到的错误是

NoSuchMethodError\u CompactLinkedHashSet没有实例方法调用。

我猜它是在尝试从多边形中提取:_getPolygons()。我不知道如何使用((){包装器,或者这是否是我应该使用的

编辑:

很抱歉,我不太清楚。我对Dart很陌生,我无法理解为什么上面的方法不起作用。但是,这确实起作用:

Expanded(
              child: Stack(
                alignment: Alignment.bottomRight,
                children: <Widget>[
                  GoogleMap(
                    mapType: MapType.normal,
                    initialCameraPosition: CameraPosition(
                      target: centerCamera,
                      zoom: zoomCamera,
                    ),
                    myLocationEnabled: true,
                    myLocationButtonEnabled: false,
                    onMapCreated: (GoogleMapController controller) {
                      googleMapController = controller;
                    },
                    onTap: (latLng) {
                      _selectCenterCircle(latLng);
                    },
                    onCameraMove: (position) {
                      centerCamera = position.target;
                      zoomCamera = position.zoom;
                    },
                    circles: _getCircles(),
                    markers: _getMarkers(),
                    polygons: _getPolygons(),
                  ),
//                  if (!drawing) _mapButtons(),
                  if (drawing)
                    Draw(
                      onDrawEnd: _onDrawPolygon,
                    ),
                ],
              ),
            ),
扩展(
子:堆栈(
对齐:对齐。右下角,
儿童:[
谷歌地图(
mapType:mapType.normal,
initialCameraPosition:CameraPosition(
目标:中央摄像机,
zoom:zoomCamera,
),
myLocationEnabled:对,
myLocationButtonEnabled:false,
onMapCreated:(谷歌地图控制器){
googleMapController=控制器;
},
onTap:(拉丁语){
_选择中心圆(板条);
},
onCameraMove:(位置){
centerCamera=position.target;
zoomCamera=position.zoom;
},
圆:_getCircles(),
标记:_getMarkers(),
多边形:_getPolygons(),
),
//如果(!drawing)\u mapButtons(),
if(图纸)
画(
onDrawEnd:_OnDraw多边形,
),
],
),
),
在我的第一组代码中,我试图实现的部分是:

如果(绘图)绘制(onDrawEnd:_onDrawPolygon)

它在没有消费者声明的情况下工作。否则无法使其工作。

您应该写:

if (dawing != null)...[
    Draw(onDrawEnd: _onDrawPolygon);
],
你应该写:

if (dawing != null)...[
    Draw(onDrawEnd: _onDrawPolygon);
],

很抱歉给您带来了困惑。此功能:

        body: Stack(children: <Widget>[
          SizedBox(
            width:
                MediaQuery.of(context).size.width, // or use fixed size like 200
            height: MediaQuery.of(context).size.height,
            child: Consumer<ProviderMaps>(builder: (context, Provmap, widget) {
              return GoogleMap(

                myLocationEnabled: true,
                compassEnabled: true,
                mapToolbarEnabled: true,
                zoomControlsEnabled: true,
                zoomGesturesEnabled: true,
                onLongPress: _addMarkerLongPressed,
                myLocationButtonEnabled: false,
                mapType: maptype,
                onTap: (latLng) {
                  _selectCenterCircle(latLng);
                },
                onMapCreated: (GoogleMapController controller) {
                  mapController = controller;
                  _controller.complete(controller);
                  isMapCreated = true;
                  changeMapMode();
                  subscription.pause();
                  changeMapType();
                  setState(() {});
                },
                initialCameraPosition:
                    CameraPosition(target: LatLng(lat, lng), zoom: 10.0),
                circles: _getCircles(),
                markers: _getMarkers(),
                polygons: _getPolygons(),
              );
            }),
          ),
          if (drawing)
            Draw(
              onDrawEnd: _onDrawPolygon,
            ),
body:Stack(子项:[
大小盒子(
宽度:
MediaQuery.of(context).size.width//或使用固定大小,如200
高度:MediaQuery.of(context).size.height,
子:消费者(构建器:(上下文、Provmap、小部件){
返回谷歌地图(
myLocationEnabled:对,
同谋:是的,
mapToolbarEnabled:true,
ZoomControl启用:对,
zoomGesturesEnabled:对,
onLongPress:\u addmarker longpress,
myLocationButtonEnabled:false,
mapType:mapType,
onTap:(拉丁语){
_选择中心圆(板条);
},
onMapCreated:(谷歌地图控制器){
mapController=控制器;
_控制器。完成(控制器);
IsmaCreated=true;
changeMapMode();
subscription.pause();
changeMapType();
setState((){});
},
初始摄像机位置:
摄像机位置(目标:LatLng(lat,lng),缩放:10.0),
圆:_getCircles(),
标记:_getMarkers(),
多边形:_getPolygons(),
);
}),
),
if(图纸)
画(
onDrawEnd:_OnDraw多边形,
),

不需要条件呈现。

很抱歉给您带来了困惑。这可以:

        body: Stack(children: <Widget>[
          SizedBox(
            width:
                MediaQuery.of(context).size.width, // or use fixed size like 200
            height: MediaQuery.of(context).size.height,
            child: Consumer<ProviderMaps>(builder: (context, Provmap, widget) {
              return GoogleMap(

                myLocationEnabled: true,
                compassEnabled: true,
                mapToolbarEnabled: true,
                zoomControlsEnabled: true,
                zoomGesturesEnabled: true,
                onLongPress: _addMarkerLongPressed,
                myLocationButtonEnabled: false,
                mapType: maptype,
                onTap: (latLng) {
                  _selectCenterCircle(latLng);
                },
                onMapCreated: (GoogleMapController controller) {
                  mapController = controller;
                  _controller.complete(controller);
                  isMapCreated = true;
                  changeMapMode();
                  subscription.pause();
                  changeMapType();
                  setState(() {});
                },
                initialCameraPosition:
                    CameraPosition(target: LatLng(lat, lng), zoom: 10.0),
                circles: _getCircles(),
                markers: _getMarkers(),
                polygons: _getPolygons(),
              );
            }),
          ),
          if (drawing)
            Draw(
              onDrawEnd: _onDrawPolygon,
            ),
body:Stack(子项:[
大小盒子(
宽度:
MediaQuery.of(context).size.width//或使用固定大小,如200
高度:MediaQuery.of(context).size.height,
子:消费者(构建器:(上下文、Provmap、小部件){
返回谷歌地图(
myLocationEnabled:对,
同谋:是的,
mapToolbarEnabled:true,
ZoomControl启用:对,
zoomGesturesEnabled:对,
onLongPress:\u addmarker longpress,
myLocationButtonEnabled:false,
mapType:mapType,
onTap:(拉丁语){
_选择中心圆(板条);
},
onMapCreated:(谷歌地图控制器控件)