import 'package:flutter/widgets.dart'; /// The composer's focus indication: a solid ring in the chat's accent colour /// along the pill's edge, so a focused field shows as such without relying /// on its caret alone. It fades in and out with focus; at rest unfocused /// nothing visible is drawn. /// /// The accent is the focus colour of the chat's own colour (the `primary` /// of a scheme seeded from it, `chatFocusRingColor`) when it has one, else /// the host's primary colour. It is drawn at full opacity, so it keeps 3:1 /// against the page for every chat colour in light and dark. 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 ring's colour while focused. 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 = 2; @override Widget build(BuildContext context) => ListenableBuilder( listenable: focus, child: child, builder: (context, child) { final focused = focus.hasFocus; // The decoration keeps the same shape and stroke while only its colour // changes, so the container lerps it into one fade. return AnimatedContainer( key: const Key('chat-composer-focus-ring'), duration: duration, curve: Curves.easeOutCubic, // Over the child: the pill's fill would otherwise cover the ring. foregroundDecoration: ShapeDecoration( shape: shape.copyWith( side: BorderSide( color: accent.withValues(alpha: focused ? 1 : 0), width: ringWidth, ), ), ), child: child, ); }, ); }