133 lines
3.9 KiB
Dart
133 lines
3.9 KiB
Dart
import 'package:flutter/material.dart';
|
|
import '../../../../shared/theme/app_theme.dart';
|
|
|
|
class MembersSearchBar extends StatefulWidget {
|
|
final TextEditingController controller;
|
|
final Function(String) onChanged;
|
|
final VoidCallback onClear;
|
|
|
|
const MembersSearchBar({
|
|
super.key,
|
|
required this.controller,
|
|
required this.onChanged,
|
|
required this.onClear,
|
|
});
|
|
|
|
@override
|
|
State<MembersSearchBar> createState() => _MembersSearchBarState();
|
|
}
|
|
|
|
class _MembersSearchBarState extends State<MembersSearchBar>
|
|
with SingleTickerProviderStateMixin {
|
|
late AnimationController _animationController;
|
|
late Animation<double> _fadeAnimation;
|
|
bool _hasText = false;
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
_animationController = AnimationController(
|
|
duration: const Duration(milliseconds: 300),
|
|
vsync: this,
|
|
);
|
|
|
|
_fadeAnimation = Tween<double>(
|
|
begin: 0.0,
|
|
end: 1.0,
|
|
).animate(CurvedAnimation(
|
|
parent: _animationController,
|
|
curve: Curves.easeInOut,
|
|
));
|
|
|
|
widget.controller.addListener(_onTextChanged);
|
|
_animationController.forward();
|
|
}
|
|
|
|
@override
|
|
void dispose() {
|
|
widget.controller.removeListener(_onTextChanged);
|
|
_animationController.dispose();
|
|
super.dispose();
|
|
}
|
|
|
|
void _onTextChanged() {
|
|
final hasText = widget.controller.text.isNotEmpty;
|
|
if (hasText != _hasText) {
|
|
setState(() {
|
|
_hasText = hasText;
|
|
});
|
|
}
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return AnimatedBuilder(
|
|
animation: _fadeAnimation,
|
|
builder: (context, child) {
|
|
return Opacity(
|
|
opacity: _fadeAnimation.value,
|
|
child: Transform.translate(
|
|
offset: Offset(0, 20 * (1 - _fadeAnimation.value)),
|
|
child: Container(
|
|
decoration: BoxDecoration(
|
|
color: Colors.white.withOpacity(0.9),
|
|
borderRadius: BorderRadius.circular(16),
|
|
boxShadow: [
|
|
BoxShadow(
|
|
color: Colors.black.withOpacity(0.1),
|
|
blurRadius: 10,
|
|
offset: const Offset(0, 2),
|
|
),
|
|
],
|
|
),
|
|
child: TextField(
|
|
controller: widget.controller,
|
|
onChanged: widget.onChanged,
|
|
style: const TextStyle(
|
|
fontSize: 16,
|
|
color: AppTheme.textPrimary,
|
|
),
|
|
decoration: InputDecoration(
|
|
hintText: 'Rechercher un membre...',
|
|
hintStyle: TextStyle(
|
|
color: AppTheme.textHint,
|
|
fontSize: 16,
|
|
),
|
|
prefixIcon: Icon(
|
|
Icons.search,
|
|
color: AppTheme.secondaryColor,
|
|
size: 24,
|
|
),
|
|
suffixIcon: _hasText
|
|
? AnimatedOpacity(
|
|
opacity: _hasText ? 1.0 : 0.0,
|
|
duration: const Duration(milliseconds: 200),
|
|
child: IconButton(
|
|
icon: Icon(
|
|
Icons.clear,
|
|
color: AppTheme.textHint,
|
|
size: 20,
|
|
),
|
|
onPressed: widget.onClear,
|
|
),
|
|
)
|
|
: null,
|
|
border: OutlineInputBorder(
|
|
borderRadius: BorderRadius.circular(16),
|
|
borderSide: BorderSide.none,
|
|
),
|
|
filled: true,
|
|
fillColor: Colors.transparent,
|
|
contentPadding: const EdgeInsets.symmetric(
|
|
horizontal: 20,
|
|
vertical: 16,
|
|
),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
},
|
|
);
|
|
}
|
|
} |