Skip to content

Commit 4c3f8be

Browse files
authored
cs/Switch using deferToChild (#331)
* switch to defer to child * simplify the set states
1 parent 1711514 commit 4c3f8be

File tree

1 file changed

+17
-19
lines changed

1 file changed

+17
-19
lines changed

lib/samples/match_viewpoint_of_geo_views/match_viewpoint_of_geo_views.dart

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -75,20 +75,23 @@ class _MatchViewpointOfGeoViewsState extends State<MatchViewpointOfGeoViews>
7575
);
7676
}
7777

78+
void updateViewInteraction(bool isMapViewInteraction) {
79+
setState(() {
80+
_isMapViewInteraction = isMapViewInteraction;
81+
_isSceneViewInteraction = !isMapViewInteraction;
82+
});
83+
}
84+
7885
List<Widget> getViews() {
7986
return [
8087
// Add a map view to the widget tree and set a controller.
8188
Expanded(
8289
child: GestureDetector(
83-
behavior: HitTestBehavior.translucent,
84-
onTapDown: (_) => setState(() {
85-
_isMapViewInteraction = true;
86-
_isSceneViewInteraction = false;
87-
}),
88-
onDoubleTapDown: (_) => setState(() {
89-
_isMapViewInteraction = true;
90-
_isSceneViewInteraction = false;
91-
}),
90+
behavior: HitTestBehavior.deferToChild,
91+
onTapDown: (_) => updateViewInteraction(true),
92+
onDoubleTapDown: (_) => updateViewInteraction(true),
93+
onLongPressDown: (_) => updateViewInteraction(true),
94+
onScaleStart:(_) => updateViewInteraction(true),
9295
child: ArcGISMapView(
9396
controllerProvider: () => _mapViewController,
9497
onMapViewReady: onMapViewReady,
@@ -98,16 +101,11 @@ class _MatchViewpointOfGeoViewsState extends State<MatchViewpointOfGeoViews>
98101
// Add a scene view to the widget tree and set a controller.
99102
Expanded(
100103
child: GestureDetector(
101-
behavior: HitTestBehavior.translucent,
102-
onDoubleTapDown: (_) => setState(() {
103-
_isMapViewInteraction = false;
104-
_isSceneViewInteraction = true;
105-
}),
106-
onTapDown: (_) => setState(() {
107-
_isMapViewInteraction = false;
108-
_isSceneViewInteraction = true;
109-
}),
110-
104+
behavior: HitTestBehavior.deferToChild,
105+
onTapDown: (_) => updateViewInteraction(false),
106+
onDoubleTapDown: (_) => updateViewInteraction(false),
107+
onLongPressDown: (_) => updateViewInteraction(false),
108+
onScaleStart:(_) => updateViewInteraction(false),
111109
child: ArcGISSceneView(
112110
controllerProvider: () => _sceneViewController,
113111
onSceneViewReady: onSceneViewReady,

0 commit comments

Comments
 (0)