import 'package:flutter/material.dart'; import '../../../../shared/theme/app_theme.dart'; /// Barre de recherche pour les membres class MembresSearchBar extends StatefulWidget { const MembresSearchBar({ super.key, required this.controller, required this.onSearch, required this.onClear, this.hintText = 'Rechercher un membre...', }); final TextEditingController controller; final ValueChanged onSearch; final VoidCallback onClear; final String hintText; @override State createState() => _MembresSearchBarState(); } class _MembresSearchBarState extends State { bool _isSearching = false; @override void initState() { super.initState(); widget.controller.addListener(_onTextChanged); } @override void dispose() { widget.controller.removeListener(_onTextChanged); super.dispose(); } void _onTextChanged() { final hasText = widget.controller.text.isNotEmpty; if (_isSearching != hasText) { setState(() { _isSearching = hasText; }); } } void _onSubmitted(String value) { if (value.trim().isNotEmpty) { widget.onSearch(value.trim()); } else { widget.onClear(); } } void _onClearPressed() { widget.controller.clear(); widget.onClear(); FocusScope.of(context).unfocus(); } @override Widget build(BuildContext context) { return Container( decoration: BoxDecoration( color: Colors.white, borderRadius: BorderRadius.circular(12), boxShadow: [ BoxShadow( color: Colors.black.withOpacity(0.1), blurRadius: 8, offset: const Offset(0, 2), ), ], ), child: TextField( controller: widget.controller, onSubmitted: _onSubmitted, textInputAction: TextInputAction.search, decoration: InputDecoration( hintText: widget.hintText, hintStyle: const TextStyle( color: AppTheme.textHint, fontSize: 16, ), prefixIcon: const Icon( Icons.search, color: AppTheme.textSecondary, ), suffixIcon: _isSearching ? IconButton( icon: const Icon( Icons.clear, color: AppTheme.textSecondary, ), onPressed: _onClearPressed, tooltip: 'Effacer la recherche', ) : null, border: OutlineInputBorder( borderRadius: BorderRadius.circular(12), borderSide: BorderSide.none, ), enabledBorder: OutlineInputBorder( borderRadius: BorderRadius.circular(12), borderSide: BorderSide.none, ), focusedBorder: OutlineInputBorder( borderRadius: BorderRadius.circular(12), borderSide: const BorderSide( color: AppTheme.primaryColor, width: 2, ), ), filled: true, fillColor: Colors.white, contentPadding: const EdgeInsets.symmetric( horizontal: 16, vertical: 12, ), ), style: const TextStyle( fontSize: 16, color: AppTheme.textPrimary, ), ), ); } }