Skip to content

Commit

Permalink
Merge pull request #66 from rasitayaz/dev
Browse files Browse the repository at this point in the history
fix child widget initializing twice when bouncing is enabled
  • Loading branch information
rasitayaz authored Sep 5, 2024
2 parents d18a982 + 9cf0fdc commit 583dd5f
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 26 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 3.2.5

* Fixed child widget initializing twice when bouncing is enabled.

## 3.2.4

* Hotfix for scrollable performance issue.
Expand Down
43 changes: 18 additions & 25 deletions lib/src/pie_menu_core.dart
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,22 @@ class _PieMenuCoreState extends State<PieMenuCore>
);

/// Controls [_bounceAnimation].
AnimationController? _bounceController;
late final _bounceController = AnimationController(
duration: _theme.childBounceDuration,
vsync: this,
);

/// Bounce animation for the child widget.
Animation<double>? _bounceAnimation;
late final _bounceAnimation = Tween(
begin: 0.0,
end: 1.0,
).animate(
CurvedAnimation(
parent: _bounceController,
curve: _theme.childBounceCurve,
reverseCurve: _theme.childBounceReverseCurve,
),
);

/// Offset of the press event.
var _pressedOffset = Offset.zero;
Expand Down Expand Up @@ -122,25 +134,6 @@ class _PieMenuCoreState extends State<PieMenuCore>
void initState() {
super.initState();
widget.controller?.addListener(_handleControllerEvent);

WidgetsBinding.instance.addPostFrameCallback((_) {
if (_theme.childBounceEnabled) {
final controller = _bounceController = AnimationController(
duration: _theme.childBounceDuration,
vsync: this,
);
_bounceAnimation = Tween(
begin: 0.0,
end: 1.0,
).animate(
CurvedAnimation(
parent: controller,
curve: _theme.childBounceCurve,
reverseCurve: _theme.childBounceReverseCurve,
),
);
}
});
}

@override
Expand All @@ -152,7 +145,7 @@ class _PieMenuCoreState extends State<PieMenuCore>
@override
void dispose() {
_overlayFadeController.dispose();
_bounceController?.dispose();
_bounceController.dispose();
_debounceTimer?.cancel();
_bounceStopwatch.stop();
widget.controller?.removeListener(_handleControllerEvent);
Expand Down Expand Up @@ -215,7 +208,7 @@ class _PieMenuCoreState extends State<PieMenuCore>
: 1,
duration: _theme.hoverDuration,
curve: Curves.ease,
child: bounceAnimation != null
child: _theme.childBounceEnabled
? BouncingWidget(
theme: _theme,
animation: bounceAnimation,
Expand Down Expand Up @@ -301,7 +294,7 @@ class _PieMenuCoreState extends State<PieMenuCore>
_bounceStopwatch.reset();
_bounceStopwatch.start();

_bounceController?.forward();
_bounceController.forward();
}

void _debounce() {
Expand All @@ -316,7 +309,7 @@ class _PieMenuCoreState extends State<PieMenuCore>
: Duration(milliseconds: minDelayMS);

_debounceTimer = Timer(debounceDelay, () {
_bounceController?.reverse();
_bounceController.reverse();
});
}

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: pie_menu
description: A Flutter package providing a highly customizable circular/radial context menu
version: 3.2.4
version: 3.2.5
homepage: https://github.com/rasitayaz/flutter-pie-menu
repository: https://github.com/rasitayaz/flutter-pie-menu
issue_tracker: https://github.com/rasitayaz/flutter-pie-menu/issues
Expand Down

0 comments on commit 583dd5f

Please sign in to comment.