import 'package:flutter/material.dart'; class SearchAppBar extends StatefulWidget { const SearchAppBar({ super.key, this.onMenuPressed, this.onLeadingPressed, this.leadingIcon = Icons.menu, this.leadingTooltip = 'MenĂº', this.leadingWidget, this.trailingWidget, this.onSearchChanged, this.searchHint = 'Buscar notas...', this.showSearch = true, this.titleText, }); final VoidCallback? onMenuPressed; final VoidCallback? onLeadingPressed; final IconData leadingIcon; final String leadingTooltip; final Widget? leadingWidget; final Widget? trailingWidget; final ValueChanged? onSearchChanged; final String searchHint; final bool showSearch; final String? titleText; @override State createState() => _SearchAppBarState(); } class _SearchAppBarState extends State { late TextEditingController _searchController; void _onSearchChanged() { setState(() {}); } @override void initState() { super.initState(); _searchController = TextEditingController()..addListener(_onSearchChanged); } @override void dispose() { _searchController.removeListener(_onSearchChanged); _searchController.dispose(); super.dispose(); } @override Widget build(BuildContext context) { return Container( decoration: BoxDecoration( color: Colors.transparent, border: Border( bottom: BorderSide( color: Colors.white.withValues(alpha: 0.12), width: 0.5, ), ), ), padding: const EdgeInsets.only(left: 8, right: 20, top: 7, bottom: 7), child: Row( children: [ IconButton( onPressed: widget.onLeadingPressed ?? widget.onMenuPressed, icon: Icon(widget.leadingIcon, color: Colors.white70, size: 20), tooltip: widget.leadingTooltip, splashRadius: 18, constraints: const BoxConstraints(minWidth: 40, minHeight: 40), ), if (widget.leadingWidget != null) ...[ const SizedBox(width: 8), Center(child: widget.leadingWidget!), ], const SizedBox(width: 8), Expanded( child: widget.showSearch ? Center( child: ConstrainedBox( constraints: const BoxConstraints(maxWidth: 600), child: TextField( controller: _searchController, onChanged: widget.onSearchChanged, style: const TextStyle(color: Colors.white, fontSize: 13), cursorColor: Colors.white70, decoration: InputDecoration( hintText: widget.searchHint, hintStyle: TextStyle( color: Colors.white.withValues(alpha: 0.5), ), suffixIcon: _searchController.text.isNotEmpty ? IconButton( icon: const Icon( Icons.clear, color: Colors.white70, size: 18, ), onPressed: () { _searchController.clear(); widget.onSearchChanged?.call(''); }, constraints: const BoxConstraints( minWidth: 36, minHeight: 36, ), ) : const Padding( padding: EdgeInsets.only(right: 8), child: Icon( Icons.search, color: Colors.white70, size: 18, ), ), border: OutlineInputBorder( borderRadius: BorderRadius.circular(8), borderSide: BorderSide( color: Colors.white.withValues(alpha: 0.2), width: 0.5, ), ), enabledBorder: OutlineInputBorder( borderRadius: BorderRadius.circular(8), borderSide: BorderSide( color: Colors.white.withValues(alpha: 0.2), width: 0.5, ), ), focusedBorder: OutlineInputBorder( borderRadius: BorderRadius.circular(8), borderSide: BorderSide( color: Colors.white.withValues(alpha: 0.4), width: 0.5, ), ), filled: true, fillColor: Colors.white.withValues(alpha: 0.05), contentPadding: const EdgeInsets.symmetric( horizontal: 12, vertical: 8, ), isDense: true, ), ), ), ) : Align( alignment: Alignment.centerLeft, child: Text( widget.titleText ?? '', style: const TextStyle( color: Colors.white, fontSize: 18, fontWeight: FontWeight.w600, ), ), ), ), if (widget.trailingWidget != null) ...[ const SizedBox(width: 16), Center(child: widget.trailingWidget!), ], ], ), ); } }