From 4f22d4f1c0314854967671ce3b3ae11e37496231 Mon Sep 17 00:00:00 2001 From: livinglist Date: Wed, 1 Apr 2026 19:29:50 -0700 Subject: [PATCH 1/2] fix: item screen background --- .../item/widgets/item_screen_background.dart | 153 +++++++++++++----- 1 file changed, 110 insertions(+), 43 deletions(-) diff --git a/lib/screens/item/widgets/item_screen_background.dart b/lib/screens/item/widgets/item_screen_background.dart index 6ba211b9..efd83d28 100644 --- a/lib/screens/item/widgets/item_screen_background.dart +++ b/lib/screens/item/widgets/item_screen_background.dart @@ -7,6 +7,7 @@ import 'package:hacki/config/constants.dart'; import 'package:hacki/cubits/cubits.dart'; import 'package:hacki/extensions/extensions.dart'; import 'package:hacki/screens/widgets/widgets.dart'; +import 'package:hacki/styles/styles.dart'; import 'package:hacki/utils/utils.dart'; class ItemScreenBackground extends StatefulWidget { @@ -29,8 +30,9 @@ class ItemScreenBackground extends StatefulWidget { class _ItemScreenBackgroundState extends State { int _shineIndex = 0; - Timer? _timer; + Timer? _startUpTimer; bool _isVisible = false; + bool _overrideCommentsStatus = false @override void initState() { @@ -39,7 +41,7 @@ class _ItemScreenBackgroundState extends State { unawaited( Future.delayed( AppDurations.oneSecond, - () { + () { if (mounted) { setState(() { _isVisible = true; @@ -48,37 +50,73 @@ class _ItemScreenBackgroundState extends State { }, ), ); + + unawaited( + Future.delayed( + AppDurations.fiveSeconds, + () { + if (mounted) { + setState(() { + _overrideCommentsStatus = true; + }); + } + }, + ), + ); } @override void dispose() { - _timer?.cancel(); + _startUpTimer?.cancel(); super.dispose(); } @override Widget build(BuildContext context) { final bool isEyeCandyEnabled = - context.read().state.isEyeCandyEnabled; + context + .read() + .state + .isEyeCandyEnabled; return BlocConsumer( listenWhen: (CommentsState previous, CommentsState current) => - previous.status != current.status, + previous.status != current.status, listener: (BuildContext context, CommentsState state) { if (state.status == CommentsStatus.allLoaded && isEyeCandyEnabled) { - _timer?.cancel(); - _timer = Timer.periodic(const Duration(milliseconds: 1200), (_) { - setState(() { - _shineIndex = (_shineIndex + 1) % (state.maxLevel + 1); - }); - }); + _startUpTimer?.cancel(); + _startUpTimer = + Timer.periodic(const Duration(milliseconds: 1200), (_) { + setState(() { + _shineIndex = (_shineIndex + 1) % (state.maxLevel + 1); + }); + }); } }, buildWhen: (CommentsState previous, CommentsState current) => - previous.maxLevel != current.maxLevel || + previous.maxLevel != current.maxLevel || previous.status != current.status, builder: (BuildContext context, CommentsState state) { if (!_isVisible || state.comments.isEmpty) { return const SizedBox.shrink(); + } else if (!_overrideCommentsStatus && + state.status == CommentsStatus.inProgress) { + return FadeIn( + child: Stack( + children: [ + Positioned( + left: Dimens.zero, + top: Dimens.zero, + bottom: Dimens.zero, + child: RotatedBox( + quarterTurns: 1, + child: LinearProgressIndicator( + minHeight: widget.indentLineWidth, + ), + ), + ), + ], + ), + ); } return FadeIn( child: Stack( @@ -87,21 +125,33 @@ class _ItemScreenBackgroundState extends State { Padding( padding: EdgeInsets.zero, child: SizedBox( - height: MediaQuery.of(context).size.height, + height: MediaQuery + .of(context) + .size + .height, width: widget.indentLineWidth, child: isEyeCandyEnabled ? AnimatedIndentLine( - color: - Theme.of(context).colorScheme.primaryContainer, - width: widget.indentLineWidth, - isShining: _shineIndex == 0, - ) + color: + Theme + .of(context) + .colorScheme + .primaryContainer, + width: widget.indentLineWidth, + isShining: _shineIndex == 0, + ) : Container( - width: widget.indentLineWidth, - height: MediaQuery.of(context).size.height, - color: - Theme.of(context).colorScheme.primaryContainer, - ), + width: widget.indentLineWidth, + height: MediaQuery + .of(context) + .size + .height, + color: + Theme + .of(context) + .colorScheme + .primaryContainer, + ), ), ), if (state.maxLevel > 0) @@ -115,30 +165,47 @@ class _ItemScreenBackgroundState extends State { : widget.indentPadding * i - widget.indentLineWidth, ), child: SizedBox( - height: MediaQuery.of(context).size.height, + height: MediaQuery + .of(context) + .size + .height, width: widget.indentLineWidth, child: isEyeCandyEnabled ? AnimatedIndentLine( - color: ColorUtils.getRainbowColor( - i, - Theme.of(context).canvasColor, - ).$1, - width: widget.indentLineWidth, - isShining: _shineIndex == i, - ) + color: ColorUtils + .getRainbowColor( + i, + Theme + .of(context) + .canvasColor, + ) + .$1, + width: widget.indentLineWidth, + isShining: _shineIndex == i, + ) : Container( - width: widget.indentLineWidth, - height: MediaQuery.of(context).size.height, - color: ColorUtils.getRainbowColor( - i, - Theme.of(context).canvasColor, - ).$1.withValues( - alpha: Theme.of(context).brightness == - Brightness.dark - ? 0.6 - : 1, - ), - ), + width: widget.indentLineWidth, + height: MediaQuery + .of(context) + .size + .height, + color: ColorUtils + .getRainbowColor( + i, + Theme + .of(context) + .canvasColor, + ) + .$1 + .withValues( + alpha: Theme + .of(context) + .brightness == + Brightness.dark + ? 0.6 + : 1, + ), + ), ), ), ], From 905a4364511683dc6e09e39a485fb532a81fc25d Mon Sep 17 00:00:00 2001 From: livinglist Date: Wed, 1 Apr 2026 19:33:03 -0700 Subject: [PATCH 2/2] update --- .../item/widgets/item_screen_background.dart | 156 +++++++----------- 1 file changed, 56 insertions(+), 100 deletions(-) diff --git a/lib/screens/item/widgets/item_screen_background.dart b/lib/screens/item/widgets/item_screen_background.dart index efd83d28..d8f43408 100644 --- a/lib/screens/item/widgets/item_screen_background.dart +++ b/lib/screens/item/widgets/item_screen_background.dart @@ -30,70 +30,55 @@ class ItemScreenBackground extends StatefulWidget { class _ItemScreenBackgroundState extends State { int _shineIndex = 0; - Timer? _startUpTimer; bool _isVisible = false; - bool _overrideCommentsStatus = false + bool _overrideCommentsStatus = false; + + Timer? _visibilityTimer; + Timer? _overrideTimer; @override void initState() { super.initState(); - unawaited( - Future.delayed( - AppDurations.oneSecond, - () { - if (mounted) { - setState(() { - _isVisible = true; - }); - } - }, - ), - ); - - unawaited( - Future.delayed( - AppDurations.fiveSeconds, - () { - if (mounted) { - setState(() { - _overrideCommentsStatus = true; - }); - } - }, - ), - ); + _visibilityTimer = Timer(AppDurations.oneSecond, () { + if (mounted) { + setState(() => _isVisible = true); + } + }); + _overrideTimer = Timer(AppDurations.fiveSeconds, () { + if (mounted) { + setState(() => _overrideCommentsStatus = true); + } + }); } @override void dispose() { - _startUpTimer?.cancel(); + _visibilityTimer?.cancel(); + _overrideTimer?.cancel(); super.dispose(); } @override Widget build(BuildContext context) { final bool isEyeCandyEnabled = - context - .read() - .state - .isEyeCandyEnabled; + context.read().state.isEyeCandyEnabled; return BlocConsumer( listenWhen: (CommentsState previous, CommentsState current) => - previous.status != current.status, + previous.status != current.status, listener: (BuildContext context, CommentsState state) { if (state.status == CommentsStatus.allLoaded && isEyeCandyEnabled) { - _startUpTimer?.cancel(); - _startUpTimer = + _visibilityTimer?.cancel(); + _visibilityTimer = Timer.periodic(const Duration(milliseconds: 1200), (_) { - setState(() { - _shineIndex = (_shineIndex + 1) % (state.maxLevel + 1); - }); - }); + setState(() { + _shineIndex = (_shineIndex + 1) % (state.maxLevel + 1); + }); + }); } }, buildWhen: (CommentsState previous, CommentsState current) => - previous.maxLevel != current.maxLevel || + previous.maxLevel != current.maxLevel || previous.status != current.status, builder: (BuildContext context, CommentsState state) { if (!_isVisible || state.comments.isEmpty) { @@ -125,33 +110,21 @@ class _ItemScreenBackgroundState extends State { Padding( padding: EdgeInsets.zero, child: SizedBox( - height: MediaQuery - .of(context) - .size - .height, + height: MediaQuery.of(context).size.height, width: widget.indentLineWidth, child: isEyeCandyEnabled ? AnimatedIndentLine( - color: - Theme - .of(context) - .colorScheme - .primaryContainer, - width: widget.indentLineWidth, - isShining: _shineIndex == 0, - ) + color: + Theme.of(context).colorScheme.primaryContainer, + width: widget.indentLineWidth, + isShining: _shineIndex == 0, + ) : Container( - width: widget.indentLineWidth, - height: MediaQuery - .of(context) - .size - .height, - color: - Theme - .of(context) - .colorScheme - .primaryContainer, - ), + width: widget.indentLineWidth, + height: MediaQuery.of(context).size.height, + color: + Theme.of(context).colorScheme.primaryContainer, + ), ), ), if (state.maxLevel > 0) @@ -165,47 +138,30 @@ class _ItemScreenBackgroundState extends State { : widget.indentPadding * i - widget.indentLineWidth, ), child: SizedBox( - height: MediaQuery - .of(context) - .size - .height, + height: MediaQuery.of(context).size.height, width: widget.indentLineWidth, child: isEyeCandyEnabled ? AnimatedIndentLine( - color: ColorUtils - .getRainbowColor( - i, - Theme - .of(context) - .canvasColor, - ) - .$1, - width: widget.indentLineWidth, - isShining: _shineIndex == i, - ) + color: ColorUtils.getRainbowColor( + i, + Theme.of(context).canvasColor, + ).$1, + width: widget.indentLineWidth, + isShining: _shineIndex == i, + ) : Container( - width: widget.indentLineWidth, - height: MediaQuery - .of(context) - .size - .height, - color: ColorUtils - .getRainbowColor( - i, - Theme - .of(context) - .canvasColor, - ) - .$1 - .withValues( - alpha: Theme - .of(context) - .brightness == - Brightness.dark - ? 0.6 - : 1, - ), - ), + width: widget.indentLineWidth, + height: MediaQuery.of(context).size.height, + color: ColorUtils.getRainbowColor( + i, + Theme.of(context).canvasColor, + ).$1.withValues( + alpha: Theme.of(context).brightness == + Brightness.dark + ? 0.6 + : 1, + ), + ), ), ), ],