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),
|
duration: const Duration(seconds: 18),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
late ThemeColors _colors = ThemeColors(widget.theme);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
if (!debugDisableLoopingAnimations) _drift.repeat();
|
if (!debugDisableLoopingAnimations) _drift.repeat();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void didUpdateWidget(SeasonBackground old) {
|
||||||
|
super.didUpdateWidget(old);
|
||||||
|
if (old.theme != widget.theme) _colors = ThemeColors(widget.theme);
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void dispose() {
|
void dispose() {
|
||||||
_drift.dispose();
|
_drift.dispose();
|
||||||
@@ -42,13 +50,12 @@ class _SeasonBackgroundState extends State<SeasonBackground>
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final colors = ThemeColors(widget.theme);
|
|
||||||
return RepaintBoundary(
|
return RepaintBoundary(
|
||||||
child: AnimatedBuilder(
|
child: AnimatedBuilder(
|
||||||
animation: _drift,
|
animation: _drift,
|
||||||
builder: (context, _) => CustomPaint(
|
builder: (context, _) => CustomPaint(
|
||||||
size: Size.infinite,
|
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);
|
paint.color = Colors.white.withValues(alpha: 0.35);
|
||||||
canvas.drawCircle(Offset.zero, s * 0.4, paint);
|
canvas.drawCircle(Offset.zero, s * 0.4, paint);
|
||||||
case 'leaves':
|
case 'leaves':
|
||||||
paint.color = const Color(0xFFE8945A).withValues(alpha: 0.35);
|
paint.color = colors.accent.withValues(alpha: 0.35);
|
||||||
canvas.drawOval(
|
canvas.drawOval(
|
||||||
Rect.fromCenter(center: Offset.zero, width: s, height: s * 0.55),
|
Rect.fromCenter(center: Offset.zero, width: s, height: s * 0.55),
|
||||||
paint);
|
paint);
|
||||||
|
|||||||
Reference in New Issue
Block a user