feat: add more easter eggs
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import 'dart:async';
|
||||
import 'dart:math';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
@@ -147,10 +148,15 @@ class ProductGrid extends StatelessWidget {
|
||||
itemBuilder: (context, index) {
|
||||
final product = products[index];
|
||||
|
||||
return ProductTile(
|
||||
product: product,
|
||||
return _FireTile(
|
||||
key: ValueKey(product.id),
|
||||
enabled: hasSelectedTab,
|
||||
onTap: () => onProductTap(product),
|
||||
builder: (onTap) => ProductTile(
|
||||
product: product,
|
||||
enabled: hasSelectedTab,
|
||||
onTap: onTap,
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
@@ -161,3 +167,128 @@ class ProductGrid extends StatelessWidget {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// Five quick taps on the same product set its tile on fire for a moment.
|
||||
class _FireTile extends StatefulWidget {
|
||||
final bool enabled;
|
||||
final VoidCallback onTap;
|
||||
final Widget Function(VoidCallback onTap) builder;
|
||||
|
||||
const _FireTile({
|
||||
super.key,
|
||||
required this.enabled,
|
||||
required this.onTap,
|
||||
required this.builder,
|
||||
});
|
||||
|
||||
@override
|
||||
State<_FireTile> createState() => _FireTileState();
|
||||
}
|
||||
|
||||
class _FireTileState extends State<_FireTile>
|
||||
with SingleTickerProviderStateMixin {
|
||||
static const _tapsNeeded = 5;
|
||||
static const _tapWindow = Duration(milliseconds: 700);
|
||||
static const _burnTime = Duration(milliseconds: 2500);
|
||||
|
||||
late final AnimationController _flicker = AnimationController(
|
||||
vsync: this,
|
||||
duration: const Duration(milliseconds: 180),
|
||||
);
|
||||
|
||||
int _tapCount = 0;
|
||||
DateTime? _lastTap;
|
||||
Timer? _burnTimer;
|
||||
|
||||
bool get _isOnFire => _burnTimer != null;
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_burnTimer?.cancel();
|
||||
_flicker.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
void _onTap() {
|
||||
widget.onTap();
|
||||
|
||||
final now = DateTime.now();
|
||||
final last = _lastTap;
|
||||
_tapCount = last != null && now.difference(last) < _tapWindow
|
||||
? _tapCount + 1
|
||||
: 1;
|
||||
_lastTap = now;
|
||||
if (_tapCount < _tapsNeeded && !_isOnFire) return;
|
||||
|
||||
// Each extra quick tap keeps it burning.
|
||||
_burnTimer?.cancel();
|
||||
_burnTimer = Timer(_burnTime, () {
|
||||
if (!mounted) return;
|
||||
_flicker.stop();
|
||||
setState(() => _burnTimer = null);
|
||||
});
|
||||
if (!_flicker.isAnimating) _flicker.repeat(reverse: true);
|
||||
setState(() {});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Stack(
|
||||
fit: StackFit.expand,
|
||||
clipBehavior: Clip.none,
|
||||
children: [
|
||||
widget.builder(_onTap),
|
||||
IgnorePointer(
|
||||
child: AnimatedOpacity(
|
||||
opacity: _isOnFire ? 1 : 0,
|
||||
duration: const Duration(milliseconds: 300),
|
||||
child: AnimatedBuilder(
|
||||
animation: _flicker,
|
||||
builder: (context, _) {
|
||||
final heat = _flicker.value;
|
||||
|
||||
return Stack(
|
||||
fit: StackFit.expand,
|
||||
clipBehavior: Clip.none,
|
||||
children: [
|
||||
DecoratedBox(
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
border: Border.all(
|
||||
color: Color.lerp(
|
||||
Colors.deepOrange,
|
||||
Colors.amber,
|
||||
heat,
|
||||
)!,
|
||||
width: 2.5,
|
||||
),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: Colors.deepOrange.withValues(
|
||||
alpha: 0.45 + 0.3 * heat,
|
||||
),
|
||||
blurRadius: 14 + 10 * heat,
|
||||
spreadRadius: 1 + 2 * heat,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
Positioned(
|
||||
left: 8,
|
||||
bottom: 6,
|
||||
child: Transform.scale(
|
||||
scale: 1 + 0.15 * heat,
|
||||
alignment: Alignment.bottomCenter,
|
||||
child: const Text('🔥', style: TextStyle(fontSize: 26)),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user