import 'package:flutter/widgets.dart'; /// The composer's focus indication: a thin ring in the chat's accent colour /// along the pill's edge and a soft glow of the same colour outside it, so /// a focused field shows as such without relying on its caret alone. Both /// fade in and out with focus; at rest unfocused nothing visible is drawn. /// /// The accent is the chat's own colour (its highlight in the list) when it /// has one, else the host's primary colour, never the pill's background: the /// ring is translucent so the same tint stays subtle on a light and a dark /// pill. class ComposerFocusRing extends StatelessWidget { const ComposerFocusRing({ super.key, required this.focus, required this.accent, required this.shape, required this.child, }); /// The field's focus node; the ring follows its [FocusNode.hasFocus]. final FocusNode focus; /// The chat's accent, at full opacity; the ring and glow fade it. final Color accent; /// The pill's shape, so the ring hugs its edge. final OutlinedBorder shape; final Widget child; /// How long the ring takes to appear or fade. static const Duration duration = Duration(milliseconds: 160); /// The ring's stroke, drawn just inside the pill's edge over its hairline. static const double ringWidth = 1.5; /// The accent's opacity in the ring while focused. static const double ringOpacity = 0.6; /// The accent's opacity in the glow while focused. static const double glowOpacity = 0.18; /// The glow's blur radius; it spreads [glowSpread] past the pill first. static const double glowBlur = 12; static const double glowSpread = 1; @override Widget build(BuildContext context) => ListenableBuilder( listenable: focus, child: child, builder: (context, child) { final focused = focus.hasFocus; // Both decorations keep the same shape, shadow and stroke while only // their colours change, so the container lerps them into one fade. return AnimatedContainer( key: const Key('chat-composer-focus-ring'), duration: duration, curve: Curves.easeOutCubic, decoration: ShapeDecoration( shape: shape, shadows: [ BoxShadow( color: accent.withValues(alpha: focused ? glowOpacity : 0), blurRadius: glowBlur, spreadRadius: glowSpread, ), ], ), // Over the child: the pill's fill would otherwise cover the ring. foregroundDecoration: ShapeDecoration( shape: shape.copyWith( side: BorderSide( color: accent.withValues(alpha: focused ? ringOpacity : 0), width: ringWidth, ), ), ), child: child, ); }, ); }