107 lines
3.0 KiB
Dart
107 lines
3.0 KiB
Dart
import 'package:flutter/cupertino.dart';
|
|
import 'package:flutter/material.dart';
|
|
|
|
import '../sessions/chat_adaptive.dart';
|
|
|
|
/// The quiet chip under an agent turn (its tools, its permissions) and the
|
|
/// native sheet it opens.
|
|
class ChatTurnChip extends StatelessWidget {
|
|
const ChatTurnChip({
|
|
super.key,
|
|
required this.chipKey,
|
|
required this.leading,
|
|
required this.label,
|
|
required this.color,
|
|
required this.semanticsLabel,
|
|
required this.sheet,
|
|
this.ellipsizeLabel = false,
|
|
});
|
|
|
|
final Key chipKey;
|
|
final Widget leading;
|
|
final String label;
|
|
final Color color;
|
|
final String semanticsLabel;
|
|
final Widget sheet;
|
|
|
|
/// Shrink a long label to one ellipsized line. Only for a chip whose parent
|
|
/// bounds its width (a turn footer's Wrap, an aligned row).
|
|
final bool ellipsizeLabel;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final cupertino =
|
|
chatControlsStyleOf(context) == ChatControlsStyle.cupertino;
|
|
final content = Row(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
leading,
|
|
const SizedBox(width: 6),
|
|
if (ellipsizeLabel)
|
|
Flexible(child: _label(maxLines: 1, overflow: TextOverflow.ellipsis))
|
|
else
|
|
_label(),
|
|
Icon(
|
|
cupertino ? CupertinoIcons.chevron_up : Icons.expand_less,
|
|
size: 14,
|
|
color: color,
|
|
),
|
|
],
|
|
);
|
|
return Semantics(
|
|
button: true,
|
|
// The child's own action is excluded with its label, so the node
|
|
// carries the activation for assistive technology.
|
|
onTap: () => _open(context, cupertino),
|
|
label: semanticsLabel,
|
|
excludeSemantics: true,
|
|
child: Padding(
|
|
padding: const EdgeInsets.only(top: 2),
|
|
child: cupertino
|
|
? CupertinoButton(
|
|
key: chipKey,
|
|
padding: const EdgeInsets.symmetric(horizontal: 4, vertical: 4),
|
|
minimumSize: Size.zero,
|
|
onPressed: () => _open(context, cupertino),
|
|
child: content,
|
|
)
|
|
: InkWell(
|
|
key: chipKey,
|
|
borderRadius: BorderRadius.circular(8),
|
|
onTap: () => _open(context, cupertino),
|
|
child: Padding(
|
|
padding: const EdgeInsets.symmetric(
|
|
horizontal: 4,
|
|
vertical: 6,
|
|
),
|
|
child: content,
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
Text _label({int? maxLines, TextOverflow? overflow}) => Text(
|
|
label,
|
|
maxLines: maxLines,
|
|
overflow: overflow,
|
|
style: TextStyle(color: color, fontSize: 13),
|
|
);
|
|
|
|
Future<void> _open(BuildContext context, bool cupertino) {
|
|
if (cupertino) {
|
|
return showCupertinoModalPopup<void>(
|
|
context: context,
|
|
builder: (_) => CupertinoPopupSurface(child: SafeArea(child: sheet)),
|
|
);
|
|
}
|
|
return showModalBottomSheet<void>(
|
|
context: context,
|
|
isScrollControlled: true,
|
|
showDragHandle: true,
|
|
useSafeArea: true,
|
|
builder: (_) => sheet,
|
|
);
|
|
}
|
|
}
|