Skip to content

Commit

Permalink
onTap() marker function support added
Browse files Browse the repository at this point in the history
  • Loading branch information
gauris26 committed Apr 23, 2021
1 parent 29f8e42 commit e111bd2
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 21 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# 3.2.0-beta.3
- onTap() marker function support added

# 3.1.3-beta.2
- Added a flag to control when animate Google Maps Camera.

Expand Down
15 changes: 11 additions & 4 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,16 @@ const kLocations = [

class SimpleMarkerAnimationExample extends StatefulWidget {
@override
SimpleMarkerAnimationExampleState createState() => SimpleMarkerAnimationExampleState();
SimpleMarkerAnimationExampleState createState() =>
SimpleMarkerAnimationExampleState();
}

class SimpleMarkerAnimationExampleState extends State<SimpleMarkerAnimationExample> {
class SimpleMarkerAnimationExampleState
extends State<SimpleMarkerAnimationExample> {
final markers = <MarkerId, Marker>{};
final controller = Completer<GoogleMapController>();
final stream = Stream.periodic(kDuration, (count) => kLocations[count]).take(kLocations.length);
final stream = Stream.periodic(kDuration, (count) => kLocations[count])
.take(kLocations.length);

@override
void initState() {
Expand All @@ -41,7 +44,8 @@ class SimpleMarkerAnimationExampleState extends State<SimpleMarkerAnimationExamp
rippleRadius: 0.2,
useRotation: false,
duration: Duration(milliseconds: 2300),
mapId: controller.future.then<int>((value) => value.mapId), //Grab Google Map Id
mapId: controller.future
.then<int>((value) => value.mapId), //Grab Google Map Id
markers: markers.values.toSet(),
child: GoogleMap(
mapType: MapType.normal,
Expand All @@ -60,6 +64,9 @@ class SimpleMarkerAnimationExampleState extends State<SimpleMarkerAnimationExamp
markerId: kMarkerId,
position: latLng,
ripple: true,
onTap: (){
print('Tapped! $latLng');
}
);
setState(() => markers[kMarkerId] = marker);
}
Expand Down
2 changes: 1 addition & 1 deletion example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ packages:
path: ".."
relative: true
source: path
version: "3.1.2-beta.1"
version: "3.1.3-beta.2"
flutter_plugin_android_lifecycle:
dependency: transitive
description:
Expand Down
4 changes: 2 additions & 2 deletions lib/core/animarker_controller_description.dart
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,17 @@ class AnimarkerControllerDescription {
MarkerListener? onMarkerAnimation,
}) =>
AnimarkerControllerDescription(
angleThreshold: animarker.angleThreshold,
curve: animarker.curve,
duration: animarker.duration,
isActiveTrip: animarker.isActiveTrip,
onMarkerAnimation: onMarkerAnimation,
onRippleAnimation: onRippleAnimation,
onStopover: onStopover,
runExpressAfter: animarker.runExpressAfter,
rippleColor: animarker.rippleColor,
rippleDuration: animarker.rippleDuration,
rippleRadius: animarker.rippleRadius,
angleThreshold: animarker.angleThreshold,
runExpressAfter: animarker.runExpressAfter,
useRotation: animarker.useRotation,
vsync: vsync,
);
Expand Down
26 changes: 16 additions & 10 deletions lib/infrastructure/anilocation_task_impl.dart
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ class AnilocationTaskImpl implements IAnilocationTask {
_isActiveTrip = description.isActiveTrip;
_useRotation = description.useRotation;

_locationCtrller = AnimationController(vsync: description.vsync, duration: description.duration);
_locationCtrller = AnimationController(
vsync: description.vsync, duration: description.duration);

_bearingTween = BearingTween.from(_locationTween);
//_bearingCtrller = AnimationController(vsync: description.vsync, duration: description.duration);
Expand All @@ -69,7 +70,8 @@ class AnilocationTaskImpl implements IAnilocationTask {

_radiusTween = Tween<double>(begin: 0, end: description.rippleRadius);

_radiusAnimation = _radiusTween.curvedAnimate(curve: Curves.linear, controller: _rippleCtrller);
_radiusAnimation = _radiusTween.curvedAnimate(
curve: Curves.linear, controller: _rippleCtrller);

_colorAnimation = ColorTween(
begin: description.rippleColor.withOpacity(1.0),
Expand Down Expand Up @@ -107,10 +109,11 @@ class AnilocationTaskImpl implements IAnilocationTask {
///or the animation is completed or dismissed
Future<void> _forward() async {
//Start animation
var canMoveForward = description.isQueueNotEmpty && !isAnimating && _locationCtrller.isCompletedOrDismissed;
var canMoveForward = description.isQueueNotEmpty &&
!isAnimating &&
_locationCtrller.isCompletedOrDismissed;

if (canMoveForward) {

var next = description.next;

var wasBeginLocationSet = _settingBeginLocation(next);
Expand All @@ -123,7 +126,7 @@ class AnilocationTaskImpl implements IAnilocationTask {
await Future.wait([
_locationCtrller.resetAndForward(),
//if (_useRotation) _bearingCtrller.resetAndForward(),
/* if (_locationTween.isRipple && _rippleCtrller.isCompletedOrDismissed && !_rippleCtrller.isAnimating)
/* if (_locationTween.isRipple && _rippleCtrller.isCompletedOrDismissed && !_rippleCtrller.isAnimating)
_rippleCtrller.resetAndForward(),*/
]);
}
Expand Down Expand Up @@ -152,7 +155,8 @@ class AnilocationTaskImpl implements IAnilocationTask {
bool _settingBeginLocation(ILatLng from) {
if (from.isEmpty) return false;

if (_locationTween.interpolator.isStopped && _locationTween.interpolator.end == from) {
if (_locationTween.interpolator.isStopped &&
_locationTween.interpolator.end == from) {
_locationTween.interpolator.begin = from;

if (_useRotation) {
Expand All @@ -169,7 +173,8 @@ class AnilocationTaskImpl implements IAnilocationTask {
if (description.isQueueNotEmpty) {
_locationCtrller.removeStatusListener(_statusListener);

var interpolator = PolynomialLocationInterpolator(points: description.values);
var interpolator =
PolynomialLocationInterpolator(points: description.values);
var multiPoint = LocationTween(interpolator: interpolator);

_swappingValue(last);
Expand Down Expand Up @@ -217,8 +222,8 @@ class AnilocationTaskImpl implements IAnilocationTask {
description.isQueueEmpty) {
var halfDuration = description.rippleDuration.inMilliseconds ~/ 2;
print('_rippleStatusListener');
await Future.delayed(
Duration(milliseconds: halfDuration), () async => await _rippleCtrller.forward(from: 0));
await Future.delayed(Duration(milliseconds: halfDuration),
() async => await _rippleCtrller.forward(from: 0));
}
}

Expand Down Expand Up @@ -285,7 +290,8 @@ class AnilocationTaskImpl implements IAnilocationTask {
}

@override
ILatLng get value => _proxyAnim.value.copyWith(bearing: _bearingAnimation.value);
ILatLng get value =>
_proxyAnim.value.copyWith(bearing: _bearingAnimation.value);

@override
bool get isAnimating => _locationCtrller.isAnimating;
Expand Down
19 changes: 16 additions & 3 deletions lib/widgets/animarker.dart
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,6 @@ class Animarker extends StatefulWidget {
/// ```
final Duration rippleDuration;


final bool shouldAnimateCamera;

Animarker({
Expand Down Expand Up @@ -335,6 +334,7 @@ class AnimarkerState extends State<Animarker> with TickerProviderStateMixin {
widget.markers
.forEach((marker) async => await _controller.pushMarker(marker));
if (widget.markers.isNotEmpty) midPoint = _calculateMidPoint();

super.initState();
}

Expand Down Expand Up @@ -368,10 +368,22 @@ class AnimarkerState extends State<Animarker> with TickerProviderStateMixin {
}

@override
void didChangeDependencies() {
void didChangeDependencies() async {
_devicePxRatio = MediaQuery.of(context).devicePixelRatio;
_zoomScale =
SphericalUtil.calculateZoomScale(_devicePxRatio, widget.zoom, midPoint);

var mapId = await widget.mapId;

GoogleMapsFlutterPlatform.instance
.onMarkerTap(mapId: mapId)
.listen((MarkerTapEvent e) {
var value = keyByMarkerId(widget.markers)[e.value];
if(value != null && value.onTap != null) {
value.onTap!();
}
});

super.didChangeDependencies();
}

Expand All @@ -388,7 +400,7 @@ class AnimarkerState extends State<Animarker> with TickerProviderStateMixin {
if (widget.onStopover != null) {
await widget.onStopover!(latLng);
}
if(widget.shouldAnimateCamera){
if (widget.shouldAnimateCamera) {
await _animateCamera();
}
}
Expand Down Expand Up @@ -431,6 +443,7 @@ class AnimarkerState extends State<Animarker> with TickerProviderStateMixin {

@override
void dispose() {
GoogleMapsFlutterPlatform.instance.dispose(mapId: 0);
_controller.dispose();
super.dispose();
}
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: flutter_animarker
description: Marker Geo-Animation solution for Google Maps.
version: 3.1.2-beta.1
version: 3.2.0-beta.3
homepage: https://github.com/gauris26/flutter_animarker
repository: https://github.com/gauris26/flutter_animarker
publish_to: https://pub.dev
Expand Down

0 comments on commit e111bd2

Please sign in to comment.