From 6c87814c07a582cb06794da5bb277b8a363cef2d Mon Sep 17 00:00:00 2001 From: ggurdin <46800240+ggurdin@users.noreply.github.com> Date: Thu, 3 Apr 2025 15:09:32 -0400 Subject: [PATCH] Sentry (#2347) * chore: replace late animations with nullable to prevent late init error * chore: remove null check operator in showToolbarButtons * chore: don't call setState in CustomSVG if not mounted --- .../analytics_misc/gain_points_animation.dart | 32 +++++++++++-------- lib/pangea/common/utils/any_state_holder.dart | 1 - lib/pangea/common/widgets/customized_svg.dart | 2 +- .../widgets/message_selection_positioner.dart | 7 ++-- 4 files changed, 22 insertions(+), 20 deletions(-) diff --git a/lib/pangea/analytics_misc/gain_points_animation.dart b/lib/pangea/analytics_misc/gain_points_animation.dart index 10fc8ed24..77d032ddd 100644 --- a/lib/pangea/analytics_misc/gain_points_animation.dart +++ b/lib/pangea/analytics_misc/gain_points_animation.dart @@ -25,9 +25,9 @@ class PointsGainedAnimationState extends State final Color? gainColor = AppConfig.gold; final Color? loseColor = Colors.red; - late AnimationController _controller; - late Animation _offsetAnimation; - late Animation _fadeAnimation; + AnimationController? _controller; + Animation? _offsetAnimation; + Animation? _fadeAnimation; final List> _swayAnimation = []; final List _initialVelocities = []; @@ -53,7 +53,7 @@ class PointsGainedAnimationState extends State end: 3.0, ).animate( CurvedAnimation( - parent: _controller, + parent: _controller!, curve: Curves.easeOut, ), ); @@ -63,7 +63,7 @@ class PointsGainedAnimationState extends State end: 0.0, ).animate( CurvedAnimation( - parent: _controller, + parent: _controller!, curve: Curves.easeIn, ), ); @@ -88,6 +88,7 @@ class PointsGainedAnimationState extends State } void initSwayAnimations() { + if (_controller == null) return; _swayAnimation.clear(); initParticleTrajectories(); @@ -98,7 +99,7 @@ class PointsGainedAnimationState extends State end: 2 * pi, ).animate( CurvedAnimation( - parent: _controller, + parent: _controller!, curve: Curves.linear, ), ), @@ -108,14 +109,14 @@ class PointsGainedAnimationState extends State @override void dispose() { - _controller.dispose(); + _controller?.dispose(); super.dispose(); } void _showPointsGained() { initSwayAnimations(); - _controller.reset(); - _controller.forward().then( + _controller?.reset(); + _controller?.forward().then( (_) { if (!mounted) return; MatrixState.pAnyState.closeOverlay(widget.targetID); @@ -125,7 +126,10 @@ class PointsGainedAnimationState extends State @override Widget build(BuildContext context) { - if (widget.points == 0) { + if (widget.points == 0 || + _controller == null || + _fadeAnimation == null || + _offsetAnimation == null) { WidgetsBinding.instance.addPostFrameCallback((_) { if (mounted) { MatrixState.pAnyState.closeOverlay(widget.targetID); @@ -151,15 +155,15 @@ class PointsGainedAnimationState extends State return Material( type: MaterialType.transparency, child: FadeTransition( - opacity: _fadeAnimation, + opacity: _fadeAnimation!, child: IgnorePointer( - ignoring: _controller.isAnimating, + ignoring: _controller!.isAnimating, child: Stack( children: List.generate(widget.points.abs(), (index) { return AnimatedBuilder( - animation: _controller, + animation: _controller!, builder: (context, child) { - final progress = _offsetAnimation.value; + final progress = _offsetAnimation!.value; final trajectory = _initialVelocities[index]; return Transform.translate( offset: Offset( diff --git a/lib/pangea/common/utils/any_state_holder.dart b/lib/pangea/common/utils/any_state_holder.dart index c0dcc2e8b..0665cef4d 100644 --- a/lib/pangea/common/utils/any_state_holder.dart +++ b/lib/pangea/common/utils/any_state_holder.dart @@ -60,7 +60,6 @@ class PangeaAnyState { } void closeOverlay([String? overlayKey]) { - debugPrint("CLOSE OVERLAY WITH KEY: $overlayKey"); final entry = overlayKey != null ? entries.firstWhereOrNull((element) => element.key == overlayKey) : entries.lastWhereOrNull( diff --git a/lib/pangea/common/widgets/customized_svg.dart b/lib/pangea/common/widgets/customized_svg.dart index 108966bda..05f03c86e 100644 --- a/lib/pangea/common/widgets/customized_svg.dart +++ b/lib/pangea/common/widgets/customized_svg.dart @@ -56,7 +56,7 @@ class _CustomizedSvgState extends State { void _startLoadingTimer() { Future.delayed(const Duration(seconds: 1), () { - if (_isLoading) { + if (_isLoading && mounted) { setState(() { _showProgressIndicator = true; }); diff --git a/lib/pangea/toolbar/widgets/message_selection_positioner.dart b/lib/pangea/toolbar/widgets/message_selection_positioner.dart index d22e2d30f..54059e86f 100644 --- a/lib/pangea/toolbar/widgets/message_selection_positioner.dart +++ b/lib/pangea/toolbar/widgets/message_selection_positioner.dart @@ -383,10 +383,9 @@ class MessageSelectionPositionerState extends State // measurement for items in the toolbar bool get showToolbarButtons => - widget.pangeaMessageEvent != null && - widget.pangeaMessageEvent!.shouldShowToolbar && - widget.pangeaMessageEvent!.event.messageType == MessageTypes.Text && - widget.pangeaMessageEvent!.messageDisplayLangIsL2; + (widget.pangeaMessageEvent?.shouldShowToolbar ?? false) && + widget.pangeaMessageEvent?.event.messageType == MessageTypes.Text && + (widget.pangeaMessageEvent?.messageDisplayLangIsL2 ?? false); bool get _hasReactions { final reactionsEvents = widget.event.aggregatedEvents(