6832ec789e
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
95 lines
2.6 KiB
Dart
95 lines
2.6 KiB
Dart
import 'package:flutter/foundation.dart';
|
|
import 'package:flutter/material.dart';
|
|
|
|
/// How long the visual bell's border takes to fade.
|
|
const Duration chatShellBellFlash = Duration(milliseconds: 300);
|
|
|
|
/// The visual bell: each time [bells] counts up (and [enabled] says so) a
|
|
/// border in the accent colour flashes round [child] and fades. Under
|
|
/// reduced motion it shows at full strength for the same time and goes,
|
|
/// without the fade.
|
|
class ChatShellBellFlash extends StatefulWidget {
|
|
const ChatShellBellFlash({
|
|
super.key,
|
|
required this.bells,
|
|
required this.enabled,
|
|
required this.child,
|
|
});
|
|
|
|
final ValueListenable<int> bells;
|
|
final bool enabled;
|
|
final Widget child;
|
|
|
|
@override
|
|
State<ChatShellBellFlash> createState() => _ChatShellBellFlashState();
|
|
}
|
|
|
|
class _ChatShellBellFlashState extends State<ChatShellBellFlash>
|
|
with SingleTickerProviderStateMixin {
|
|
late final AnimationController _flash = AnimationController(
|
|
vsync: this,
|
|
duration: chatShellBellFlash,
|
|
value: 0,
|
|
);
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
widget.bells.addListener(_rang);
|
|
}
|
|
|
|
@override
|
|
void didUpdateWidget(ChatShellBellFlash old) {
|
|
super.didUpdateWidget(old);
|
|
if (old.bells != widget.bells) {
|
|
old.bells.removeListener(_rang);
|
|
widget.bells.addListener(_rang);
|
|
}
|
|
}
|
|
|
|
@override
|
|
void dispose() {
|
|
widget.bells.removeListener(_rang);
|
|
_flash.dispose();
|
|
super.dispose();
|
|
}
|
|
|
|
void _rang() {
|
|
if (widget.enabled && mounted) _flash.reverse(from: 1);
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final color = Theme.of(context).colorScheme.primary;
|
|
// Reduced motion: the border holds at full strength, then goes.
|
|
final steady = MediaQuery.maybeDisableAnimationsOf(context) ?? false;
|
|
return Stack(
|
|
fit: StackFit.passthrough,
|
|
children: [
|
|
widget.child,
|
|
Positioned.fill(
|
|
child: IgnorePointer(
|
|
child: AnimatedBuilder(
|
|
animation: _flash,
|
|
builder: (context, _) => _flash.value == 0
|
|
? const SizedBox.shrink()
|
|
: DecoratedBox(
|
|
key: const ValueKey('terminal-bell-flash'),
|
|
decoration: BoxDecoration(
|
|
borderRadius: BorderRadius.circular(8),
|
|
border: Border.all(
|
|
color: color.withValues(
|
|
alpha: steady ? 1 : _flash.value,
|
|
),
|
|
width: 2,
|
|
),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
],
|
|
);
|
|
}
|
|
}
|