From 9cf0fdc553e0aad147f136d3a1f565dcea9846c1 Mon Sep 17 00:00:00 2001 From: rasitayaz Date: Thu, 5 Sep 2024 11:23:50 +0300 Subject: [PATCH] fix child widget initializing twice when bouncing is enabled --- CHANGELOG.md | 4 ++++ lib/src/pie_menu_core.dart | 43 ++++++++++++++++---------------------- pubspec.yaml | 2 +- 3 files changed, 23 insertions(+), 26 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8384e9f..0e13436 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 3.2.5 + +* Fixed child widget initializing twice when bouncing is enabled. + ## 3.2.4 * Hotfix for scrollable performance issue. diff --git a/lib/src/pie_menu_core.dart b/lib/src/pie_menu_core.dart index c1d0235..9a9e658 100644 --- a/lib/src/pie_menu_core.dart +++ b/lib/src/pie_menu_core.dart @@ -78,10 +78,22 @@ class _PieMenuCoreState extends State ); /// Controls [_bounceAnimation]. - AnimationController? _bounceController; + late final _bounceController = AnimationController( + duration: _theme.childBounceDuration, + vsync: this, + ); /// Bounce animation for the child widget. - Animation? _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; @@ -122,25 +134,6 @@ class _PieMenuCoreState extends State 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 @@ -152,7 +145,7 @@ class _PieMenuCoreState extends State @override void dispose() { _overlayFadeController.dispose(); - _bounceController?.dispose(); + _bounceController.dispose(); _debounceTimer?.cancel(); _bounceStopwatch.stop(); widget.controller?.removeListener(_handleControllerEvent); @@ -215,7 +208,7 @@ class _PieMenuCoreState extends State : 1, duration: _theme.hoverDuration, curve: Curves.ease, - child: bounceAnimation != null + child: _theme.childBounceEnabled ? BouncingWidget( theme: _theme, animation: bounceAnimation, @@ -301,7 +294,7 @@ class _PieMenuCoreState extends State _bounceStopwatch.reset(); _bounceStopwatch.start(); - _bounceController?.forward(); + _bounceController.forward(); } void _debounce() { @@ -316,7 +309,7 @@ class _PieMenuCoreState extends State : Duration(milliseconds: minDelayMS); _debounceTimer = Timer(debounceDelay, () { - _bounceController?.reverse(); + _bounceController.reverse(); }); } diff --git a/pubspec.yaml b/pubspec.yaml index b8c8222..3b07a7e 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -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