Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WIP: Gestures update - two finger rotation / interactions filter / ma…
…p events (#719) * Add two finger rotation support * Add InteractiveFlags * Add example page * Emit MapEvents basic * Update interactive test page * update interactive page * Emit move / rotate events * Emit rotation events * Rotate only when rotationThreshold reached * Update examples * add some document * fix some event's source * typo fix * Call onRotationChanged correctly * Fix arbitrary jumps when map is panned in rotated state * tap / longPress / double tap use rotated offset / fix GestureDetector corners * code refactor / organize * Wip-gesture race: time to test on real device * Fix multi finger gesture race * Reset gesture winner correctly * Use MultiFingerGesture during gesture race * update MultiFingerGesture doc * add debugMultiFingerGestureWinner / enableMultiFingerGestureRace * Do not override original start point * mapEventStream do not rely on MapController.ready * emit MapEventFlingAnimationStart correctly * remove expensive _positionedTapDetectorKey * rebuild layers just once when Move and Rotate happens at the same time * use different eventKey in example * GestureDetector isn't rotated anymore * Correct fling animation when map is rotated * Make rotation operation cheaper * add rotate flag for layers * Revert "add rotate flag for layers" This reverts commit 9e550fe. * create rotate and non rotate layers * Use Stream<Null> rebuild instead of dynamic * #736 fix - rebuild layers when size changed with new pixelOrigin * #736 fix2 - do not call onMoveSink after init * #736 fix2 - handle rebuild layers without _updateSizeByOriginalSizeAndRotation method * fix emit MapEventMove while multifinger * try to fix dartanalyzer for Travis * try to fix dartanalyzer for Travis 2 * Update tile_layer.dart Co-authored-by: John Ryan <ryjohn@google.com>
- Loading branch information
Showing
29 changed files
with
1,561 additions
and
325 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,191 @@ | ||
import 'dart:async'; | ||
|
||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_map/flutter_map.dart'; | ||
import 'package:latlong/latlong.dart'; | ||
|
||
import '../widgets/drawer.dart'; | ||
|
||
class InteractiveTestPage extends StatefulWidget { | ||
static const String route = 'interactive_test_page'; | ||
|
||
@override | ||
State createState() { | ||
return _InteractiveTestPageState(); | ||
} | ||
} | ||
|
||
class _InteractiveTestPageState extends State<InteractiveTestPage> { | ||
MapController mapController; | ||
|
||
// Enable pinchZoom and doubleTapZoomBy by default | ||
int flags = InteractiveFlag.pinchZoom | InteractiveFlag.doubleTapZoom; | ||
|
||
StreamSubscription<MapEvent> subscription; | ||
|
||
@override | ||
void initState() { | ||
super.initState(); | ||
mapController = MapController(); | ||
|
||
subscription = mapController.mapEventStream.listen(onMapEvent); | ||
} | ||
|
||
@override | ||
void dispose() { | ||
subscription.cancel(); | ||
|
||
super.dispose(); | ||
} | ||
|
||
void onMapEvent(MapEvent mapEvent) { | ||
if (mapEvent is! MapEventMove && mapEvent is! MapEventRotate) { | ||
// do not flood console with move and rotate events | ||
print(mapEvent); | ||
} | ||
} | ||
|
||
void updateFlags(int flag) { | ||
if (InteractiveFlag.hasFlag(flags, flag)) { | ||
// remove flag from flags | ||
flags &= ~flag; | ||
} else { | ||
// add flag to flags | ||
flags |= flag; | ||
} | ||
} | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return Scaffold( | ||
appBar: AppBar(title: Text('Test out Interactive flags!')), | ||
drawer: buildDrawer(context, InteractiveTestPage.route), | ||
body: Padding( | ||
padding: EdgeInsets.all(8.0), | ||
child: Column( | ||
children: [ | ||
Row( | ||
mainAxisAlignment: MainAxisAlignment.spaceBetween, | ||
children: <Widget>[ | ||
MaterialButton( | ||
child: Text('Drag'), | ||
color: InteractiveFlag.hasFlag(flags, InteractiveFlag.drag) | ||
? Colors.greenAccent | ||
: Colors.redAccent, | ||
onPressed: () { | ||
setState(() { | ||
updateFlags(InteractiveFlag.drag); | ||
}); | ||
}, | ||
), | ||
MaterialButton( | ||
child: Text('Fling'), | ||
color: InteractiveFlag.hasFlag( | ||
flags, InteractiveFlag.flingAnimation) | ||
? Colors.greenAccent | ||
: Colors.redAccent, | ||
onPressed: () { | ||
setState(() { | ||
updateFlags(InteractiveFlag.flingAnimation); | ||
}); | ||
}, | ||
), | ||
MaterialButton( | ||
child: Text('Pinch move'), | ||
color: | ||
InteractiveFlag.hasFlag(flags, InteractiveFlag.pinchMove) | ||
? Colors.greenAccent | ||
: Colors.redAccent, | ||
onPressed: () { | ||
setState(() { | ||
updateFlags(InteractiveFlag.pinchMove); | ||
}); | ||
}, | ||
), | ||
], | ||
), | ||
Row( | ||
mainAxisAlignment: MainAxisAlignment.spaceBetween, | ||
children: <Widget>[ | ||
MaterialButton( | ||
child: Text('Double tap zoom'), | ||
color: InteractiveFlag.hasFlag( | ||
flags, InteractiveFlag.doubleTapZoom) | ||
? Colors.greenAccent | ||
: Colors.redAccent, | ||
onPressed: () { | ||
setState(() { | ||
updateFlags(InteractiveFlag.doubleTapZoom); | ||
}); | ||
}, | ||
), | ||
MaterialButton( | ||
child: Text('Rotate'), | ||
color: InteractiveFlag.hasFlag(flags, InteractiveFlag.rotate) | ||
? Colors.greenAccent | ||
: Colors.redAccent, | ||
onPressed: () { | ||
setState(() { | ||
updateFlags(InteractiveFlag.rotate); | ||
}); | ||
}, | ||
), | ||
MaterialButton( | ||
child: Text('Pinch zoom'), | ||
color: | ||
InteractiveFlag.hasFlag(flags, InteractiveFlag.pinchZoom) | ||
? Colors.greenAccent | ||
: Colors.redAccent, | ||
onPressed: () { | ||
setState(() { | ||
updateFlags(InteractiveFlag.pinchZoom); | ||
}); | ||
}, | ||
), | ||
], | ||
), | ||
Padding( | ||
padding: EdgeInsets.only(top: 8.0, bottom: 8.0), | ||
child: Center( | ||
child: StreamBuilder<MapEvent>( | ||
stream: mapController.mapEventStream, | ||
builder: | ||
(BuildContext context, AsyncSnapshot<MapEvent> snapshot) { | ||
if (!snapshot.hasData) { | ||
return Text( | ||
'Current event: none\nSource: none', | ||
textAlign: TextAlign.center, | ||
); | ||
} | ||
|
||
return Text( | ||
'Current event: ${snapshot.data.runtimeType}\nSource: ${snapshot.data.source}', | ||
textAlign: TextAlign.center, | ||
); | ||
}, | ||
), | ||
), | ||
), | ||
Flexible( | ||
child: FlutterMap( | ||
mapController: mapController, | ||
options: MapOptions( | ||
center: LatLng(51.5, -0.09), | ||
zoom: 11.0, | ||
interactiveFlags: flags, | ||
), | ||
layers: [ | ||
TileLayerOptions( | ||
urlTemplate: | ||
'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', | ||
subdomains: ['a', 'b', 'c'], | ||
), | ||
], | ||
), | ||
), | ||
], | ||
), | ||
), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.