feat: add more easter eggs
This commit is contained in:
+128
-28
@@ -8,6 +8,7 @@ import 'package:flutter_slidable/flutter_slidable.dart';
|
||||
import '../../l10n/app_localizations.dart';
|
||||
import '../../models/bar_tab.dart';
|
||||
import '../../models/tab_item.dart';
|
||||
import '../../utils/easter_eggs.dart';
|
||||
import '../../utils/money.dart';
|
||||
import '../../utils/name_index.dart';
|
||||
import 'selected_tab_details.dart';
|
||||
@@ -578,7 +579,7 @@ class _TabCard extends StatelessWidget {
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Text(
|
||||
tab.customerName,
|
||||
customerDisplayName(tab.customerName),
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: TextStyle(
|
||||
@@ -602,7 +603,7 @@ class _TabCard extends StatelessWidget {
|
||||
}
|
||||
}
|
||||
|
||||
class _LetterIndexBar extends StatelessWidget {
|
||||
class _LetterIndexBar extends StatefulWidget {
|
||||
final Set<String> availableLetters;
|
||||
final String? activeLetter;
|
||||
final bool isTouched;
|
||||
@@ -617,20 +618,80 @@ class _LetterIndexBar extends StatelessWidget {
|
||||
required this.onReleased,
|
||||
});
|
||||
|
||||
@override
|
||||
State<_LetterIndexBar> createState() => _LetterIndexBarState();
|
||||
}
|
||||
|
||||
class _LetterIndexBarState extends State<_LetterIndexBar>
|
||||
with SingleTickerProviderStateMixin {
|
||||
static final _zIndex = indexLetters.indexOf('Z');
|
||||
|
||||
/// Sliding (rather than tapping) leaves a fading trail of rainbow dots.
|
||||
bool _isSliding = false;
|
||||
|
||||
/// Progress of an A → Z → A slide: null once broken, else whether Z was hit.
|
||||
bool? _reachedZ;
|
||||
|
||||
/// Sweeps a rainbow down the bar after a full A → Z → A slide.
|
||||
late final AnimationController _wave = AnimationController(
|
||||
vsync: this,
|
||||
duration: const Duration(milliseconds: 1400),
|
||||
);
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_wave.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
void _setSliding(bool value) {
|
||||
if (_isSliding != value) setState(() => _isSliding = value);
|
||||
}
|
||||
|
||||
void _trackRainbowRoad(int index, {bool isStart = false}) {
|
||||
if (isStart) {
|
||||
_reachedZ = index == 0 ? false : null;
|
||||
} else if (_reachedZ == false && index >= _zIndex) {
|
||||
_reachedZ = true;
|
||||
} else if (_reachedZ == true && index == 0) {
|
||||
_reachedZ = null;
|
||||
_wave.forward(from: 0);
|
||||
ScaffoldMessenger.maybeOf(context)
|
||||
?..hideCurrentSnackBar()
|
||||
..showSnackBar(
|
||||
SnackBar(content: Text(AppLocalizations.of(context).rainbowRoad)),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
static Color _rainbowAt(int index) => HSVColor.fromAHSV(
|
||||
1,
|
||||
360 * index / indexLetters.length,
|
||||
0.75,
|
||||
0.95,
|
||||
).toColor();
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = Theme.of(context);
|
||||
final scheme = theme.colorScheme;
|
||||
final onLetterSelected = widget.onLetterSelected;
|
||||
|
||||
void onReleased() {
|
||||
_setSliding(false);
|
||||
widget.onReleased();
|
||||
}
|
||||
|
||||
return LayoutBuilder(
|
||||
builder: (context, constraints) {
|
||||
final letterHeight = constraints.maxHeight / indexLetters.length;
|
||||
final fontSize = min(13.0, letterHeight * 0.65);
|
||||
|
||||
String letterAt(Offset position) {
|
||||
final index = (position.dy / letterHeight).floor();
|
||||
return indexLetters[index.clamp(0, indexLetters.length - 1)];
|
||||
}
|
||||
int indexAt(Offset position) => (position.dy / letterHeight)
|
||||
.floor()
|
||||
.clamp(0, indexLetters.length - 1);
|
||||
|
||||
String letterAt(Offset position) => indexLetters[indexAt(position)];
|
||||
|
||||
return GestureDetector(
|
||||
behavior: HitTestBehavior.opaque,
|
||||
@@ -638,31 +699,49 @@ class _LetterIndexBar extends StatelessWidget {
|
||||
onLetterSelected(letterAt(details.localPosition)),
|
||||
onTapUp: (_) => onReleased(),
|
||||
onTapCancel: onReleased,
|
||||
onVerticalDragStart: (details) =>
|
||||
onLetterSelected(letterAt(details.localPosition)),
|
||||
onVerticalDragUpdate: (details) =>
|
||||
onLetterSelected(letterAt(details.localPosition)),
|
||||
onVerticalDragStart: (details) {
|
||||
_setSliding(true);
|
||||
_trackRainbowRoad(indexAt(details.localPosition), isStart: true);
|
||||
onLetterSelected(letterAt(details.localPosition));
|
||||
},
|
||||
onVerticalDragUpdate: (details) {
|
||||
_trackRainbowRoad(indexAt(details.localPosition));
|
||||
onLetterSelected(letterAt(details.localPosition));
|
||||
},
|
||||
onVerticalDragEnd: (_) => onReleased(),
|
||||
onVerticalDragCancel: onReleased,
|
||||
child: SizedBox(
|
||||
width: 28,
|
||||
child: Column(
|
||||
children: [
|
||||
for (final letter in indexLetters)
|
||||
SizedBox(
|
||||
height: letterHeight,
|
||||
child: Center(
|
||||
child: _IndexLetter(
|
||||
letter: letter,
|
||||
fontSize: fontSize,
|
||||
isActive: letter == activeLetter,
|
||||
isTouched: isTouched,
|
||||
hasNames: availableLetters.contains(letter),
|
||||
scheme: scheme,
|
||||
child: AnimatedBuilder(
|
||||
animation: _wave,
|
||||
builder: (context, _) {
|
||||
final isWaving = _wave.isAnimating;
|
||||
// Runs past both ends so the first and last dots fade too.
|
||||
final crest = _wave.value * (indexLetters.length + 8) - 2;
|
||||
|
||||
return Column(
|
||||
children: [
|
||||
for (final (index, letter) in indexLetters.indexed)
|
||||
SizedBox(
|
||||
height: letterHeight,
|
||||
child: Center(
|
||||
child: _IndexLetter(
|
||||
letter: letter,
|
||||
fontSize: fontSize,
|
||||
isActive: letter == widget.activeLetter,
|
||||
isTouched: widget.isTouched,
|
||||
isLit: isWaving && (crest - index).abs() < 1.5,
|
||||
hasNames: widget.availableLetters.contains(letter),
|
||||
rainbowColor: _isSliding || isWaving
|
||||
? _rainbowAt(index)
|
||||
: null,
|
||||
scheme: scheme,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
@@ -676,7 +755,13 @@ class _IndexLetter extends StatelessWidget {
|
||||
final double fontSize;
|
||||
final bool isActive;
|
||||
final bool isTouched;
|
||||
|
||||
/// Lit by the rainbow road wave, regardless of touch.
|
||||
final bool isLit;
|
||||
final bool hasNames;
|
||||
|
||||
/// Set while sliding: the dot takes this color and fades out slowly.
|
||||
final Color? rainbowColor;
|
||||
final ColorScheme scheme;
|
||||
|
||||
const _IndexLetter({
|
||||
@@ -684,13 +769,19 @@ class _IndexLetter extends StatelessWidget {
|
||||
required this.fontSize,
|
||||
required this.isActive,
|
||||
required this.isTouched,
|
||||
this.isLit = false,
|
||||
required this.hasNames,
|
||||
this.rainbowColor,
|
||||
required this.scheme,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final rainbowColor = this.rainbowColor;
|
||||
final showDot = (isActive && isTouched) || isLit;
|
||||
final color = switch ((isActive, isTouched, hasNames)) {
|
||||
_ when isLit && rainbowColor != null => Colors.white,
|
||||
(true, true, _) when rainbowColor != null => Colors.white,
|
||||
(true, true, _) => scheme.onPrimary,
|
||||
(true, false, _) => scheme.primary,
|
||||
(false, _, true) => scheme.onSurface,
|
||||
@@ -698,13 +789,22 @@ class _IndexLetter extends StatelessWidget {
|
||||
};
|
||||
|
||||
return AnimatedContainer(
|
||||
duration: const Duration(milliseconds: 120),
|
||||
// Applies to the transition being started, so a sliding dot appears
|
||||
// instantly but lingers on its way out.
|
||||
duration: Duration(
|
||||
milliseconds: rainbowColor != null && !showDot ? 600 : 120,
|
||||
),
|
||||
width: fontSize * 1.8,
|
||||
height: fontSize * 1.8,
|
||||
alignment: Alignment.center,
|
||||
decoration: BoxDecoration(
|
||||
shape: BoxShape.circle,
|
||||
color: isActive && isTouched ? scheme.primary : Colors.transparent,
|
||||
color: switch ((showDot, rainbowColor)) {
|
||||
(true, final Color rainbow?) => rainbow,
|
||||
(true, null) => scheme.primary,
|
||||
(false, final Color rainbow?) => rainbow.withValues(alpha: 0),
|
||||
(false, null) => Colors.transparent,
|
||||
},
|
||||
),
|
||||
child: Text(
|
||||
letter,
|
||||
|
||||
Reference in New Issue
Block a user