import 'package:flutter/material.dart'; /// 搜索框内嵌的「已生效搜索词」标签:紧凑圆角 chip + ✕ 删除按钮。 /// /// 用于列表屏搜索框 [InputDecoration.prefix],仅展示单个搜索词; /// 点 ✕ 触发 [onDeleted] 清除搜索。 class SearchChip extends StatelessWidget { const SearchChip({super.key, required this.label, required this.onDeleted}); final String label; final VoidCallback onDeleted; @override Widget build(BuildContext context) { final theme = Theme.of(context); final bg = theme.colorScheme.primary.withValues(alpha: 0.12); final fg = theme.colorScheme.primary; return Container( padding: const EdgeInsets.only(left: 8, right: 2, top: 2, bottom: 2), decoration: BoxDecoration( color: bg, borderRadius: BorderRadius.circular(12), ), child: Row( mainAxisSize: MainAxisSize.min, children: [ ConstrainedBox( constraints: const BoxConstraints(maxWidth: 120), child: Text( label, maxLines: 1, overflow: TextOverflow.ellipsis, style: TextStyle( fontSize: 12, color: fg, fontWeight: FontWeight.w500, ), ), ), InkResponse( onTap: onDeleted, radius: 14, child: Padding( padding: const EdgeInsets.all(2), child: Icon(Icons.close, size: 14, color: fg), ), ), ], ), ); } }