Skip to content

Commit

Permalink
feat(fm-compass): add onPressedOverridesDefault parameter (#49)
Browse files Browse the repository at this point in the history
* add overriding disabled option

* fix analysis

* rename and use pattern matching
  • Loading branch information
nghiashiyi authored Oct 20, 2024
1 parent be687b5 commit c2e20a1
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions flutter_map_compass/lib/src/map_compass.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class MapCompass extends StatefulWidget {
this.rotationDuration = const Duration(seconds: 1),
this.animationCurve = Curves.fastOutSlowIn,
this.onPressed,
this.onPressedOverridesDefault = true,
this.hideIfRotatedNorth = false,
this.alignment = Alignment.topRight,
this.padding = const EdgeInsets.all(10),
Expand All @@ -26,6 +27,7 @@ class MapCompass extends StatefulWidget {
super.key,
this.onPressed,
this.hideIfRotatedNorth = false,
this.onPressedOverridesDefault = true,
this.rotationDuration = const Duration(seconds: 1),
this.animationCurve = Curves.fastOutSlowIn,
this.alignment = Alignment.topRight,
Expand Down Expand Up @@ -73,6 +75,11 @@ class MapCompass extends StatefulWidget {
/// The curve of the rotation animation.
final Curve animationCurve;

/// When [onPressedOverridesDefault] is true, [onPressed] will be override
/// the default rotation.
///
final bool onPressedOverridesDefault;

@override
State<MapCompass> createState() => _MapCompassState();
}
Expand Down Expand Up @@ -101,8 +108,18 @@ class _MapCompassState extends State<MapCompass> with TickerProviderStateMixin {
alignment: Alignment.center,
padding: EdgeInsets.zero,
icon: widget.icon,
onPressed:
widget.onPressed ?? () => _resetRotation(context, camera),
onPressed: () {
if (widget.onPressedOverridesDefault) {
if (widget.onPressed case final VoidCallback onPressed) {
onPressed();
} else {
_resetRotation(context, camera);
}
} else {
_resetRotation(context, camera);
widget.onPressed?.call();
}
},
),
),
),
Expand Down

0 comments on commit c2e20a1

Please sign in to comment.