perf: cache ThemeColors across frames; theme-tint leaf particles
Fix 1: Stop allocating ThemeColors on every animation frame by caching it in _colors field and updating only when theme changes via didUpdateWidget. Fix 2: Leaf particles now follow the season accent color instead of hardcoded orange, maintaining visual consistency with theme changes. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -28,12 +28,20 @@ class _SeasonBackgroundState extends State<SeasonBackground>
|
||||
duration: const Duration(seconds: 18),
|
||||
);
|
||||
|
||||
late ThemeColors _colors = ThemeColors(widget.theme);
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
if (!debugDisableLoopingAnimations) _drift.repeat();
|
||||
}
|
||||
|
||||
@override
|
||||
void didUpdateWidget(SeasonBackground old) {
|
||||
super.didUpdateWidget(old);
|
||||
if (old.theme != widget.theme) _colors = ThemeColors(widget.theme);
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_drift.dispose();
|
||||
@@ -42,13 +50,12 @@ class _SeasonBackgroundState extends State<SeasonBackground>
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final colors = ThemeColors(widget.theme);
|
||||
return RepaintBoundary(
|
||||
child: AnimatedBuilder(
|
||||
animation: _drift,
|
||||
builder: (context, _) => CustomPaint(
|
||||
size: Size.infinite,
|
||||
painter: _AmbiencePainter(colors: colors, t: _drift.value),
|
||||
painter: _AmbiencePainter(colors: _colors, t: _drift.value),
|
||||
),
|
||||
),
|
||||
);
|
||||
@@ -110,7 +117,7 @@ class _AmbiencePainter extends CustomPainter {
|
||||
paint.color = Colors.white.withValues(alpha: 0.35);
|
||||
canvas.drawCircle(Offset.zero, s * 0.4, paint);
|
||||
case 'leaves':
|
||||
paint.color = const Color(0xFFE8945A).withValues(alpha: 0.35);
|
||||
paint.color = colors.accent.withValues(alpha: 0.35);
|
||||
canvas.drawOval(
|
||||
Rect.fromCenter(center: Offset.zero, width: s, height: s * 0.55),
|
||||
paint);
|
||||
|
||||
Reference in New Issue
Block a user