import 'package:flutter/material.dart'; import 'package:wanisdriver/widgets/custom_text.dart'; import '../utils/colors.dart'; class GenderSelector extends StatefulWidget { final String? initialValue; final void Function(String) onChanged; const GenderSelector({ Key? key, this.initialValue, required this.onChanged, }) : super(key: key); @override State createState() => _GenderSelectorState(); } class _GenderSelectorState extends State with TickerProviderStateMixin { String? _selectedGender; late AnimationController _maleController; late AnimationController _femaleController; late Animation _maleScale; late Animation _femaleScale; @override void initState() { super.initState(); // _selectedGender = widget.initialValue; // REMOVE THIS LINE _maleController = AnimationController( duration: const Duration(milliseconds: 200), vsync: this, ); _femaleController = AnimationController( duration: const Duration(milliseconds: 200), vsync: this, ); _maleScale = Tween(begin: 1.0, end: 1.05).animate( CurvedAnimation(parent: _maleController, curve: Curves.easeInOut), ); _femaleScale = Tween(begin: 1.0, end: 1.05).animate( CurvedAnimation(parent: _femaleController, curve: Curves.easeInOut), ); } @override void dispose() { _maleController.dispose(); _femaleController.dispose(); super.dispose(); } void _selectGender(String gender) { setState(() { _selectedGender = gender; }); widget.onChanged(gender); if (gender == 'MALE') { _maleController.forward().then((_) => _maleController.reverse()); } else { _femaleController.forward().then((_) => _femaleController.reverse()); } } @override Widget build(BuildContext context) { final theme = Theme.of(context); final isDarkMode = theme.brightness == Brightness.dark; return Padding( padding: const EdgeInsets.symmetric(horizontal: 5.0), child: Row( children: [ Expanded( child: AnimatedBuilder( animation: _maleScale, builder: (context, child) { return Transform.scale( scale: _maleScale.value, child: GestureDetector( onTap: () => _selectGender('MALE'), child: AnimatedContainer( duration: const Duration(milliseconds: 300), curve: Curves.easeInOut, padding: const EdgeInsets.symmetric( horizontal: 16, vertical: 16, ), decoration: BoxDecoration( color: _selectedGender == 'MALE' ? const Color(0xFF5B259F).withOpacity(0.1) : isDarkMode ? AppColors.blackBackgroundColor : AppColors.darkSecondaryText2, borderRadius: BorderRadius.circular(12), border: Border.all( color: _selectedGender == 'MALE' ? const Color(0xFF5B259F) : isDarkMode ? Colors.grey.shade300 : AppColors.darkSecondaryText2, width: _selectedGender == 'MALE' ? 2 : 1.5, ), boxShadow: _selectedGender == 'MALE' ? [ BoxShadow( color: const Color(0xFF5B259F).withOpacity(0.2), blurRadius: 8, offset: const Offset(0, 4), ), ] : [ BoxShadow( color: Colors.black.withOpacity(0.05), blurRadius: 4, offset: const Offset(0, 2), ), ], ), child: Row( mainAxisAlignment: MainAxisAlignment.center, children: [ AnimatedContainer( duration: const Duration(milliseconds: 300), width: 16, height: 16, decoration: BoxDecoration( shape: BoxShape.circle, border: Border.all( color: _selectedGender == 'MALE' ? const Color(0xFF5B259F) : Colors.grey.shade300, width: 2, ), color: _selectedGender == 'MALE' ? const Color(0xFF5B259F) : Colors.white, ), child: _selectedGender == 'MALE' ? const Icon( Icons.check, size: 12, color: Colors.white, ) : null, ), const SizedBox(width: 12), Row( children: [ Icon( Icons.male, color: _selectedGender == 'MALE' ? const Color(0xFF5B259F) : Colors.grey.shade500, size: 14, ), const SizedBox(width: 6), Txt( text: 'MALE', style: TextStyle( fontFamily: 'Poppins', fontSize: 16, fontWeight: _selectedGender == 'MALE' ? FontWeight.w600 : FontWeight.w500, color: _selectedGender == 'MALE' ? const Color(0xFF5B259F) : Colors.grey.shade500, ), ), ], ), ], ), ), ), ); }, ), ), const SizedBox(width: 12), Expanded( child: AnimatedBuilder( animation: _femaleScale, builder: (context, child) { return Transform.scale( scale: _femaleScale.value, child: GestureDetector( onTap: () => _selectGender('FEMALE'), child: AnimatedContainer( duration: const Duration(milliseconds: 300), curve: Curves.easeInOut, padding: const EdgeInsets.symmetric( horizontal: 16, vertical: 16, ), decoration: BoxDecoration( color: _selectedGender == 'FEMALE' ? const Color(0xFF5B259F).withOpacity(0.1) : isDarkMode ? AppColors.blackBackgroundColor : AppColors.darkSecondaryText2, borderRadius: BorderRadius.circular(12), border: Border.all( color: _selectedGender == 'FEMALE' ? const Color(0xFF5B259F) : isDarkMode ? Colors.grey.shade300 : AppColors.darkSecondaryText2, width: _selectedGender == 'FEMALE' ? 2 : 1.5, ), boxShadow: _selectedGender == 'FEMALE' ? [ BoxShadow( color: const Color(0xFF5B259F).withOpacity(0.2), blurRadius: 8, offset: const Offset(0, 4), ), ] : [ BoxShadow( color: Colors.black.withOpacity(0.05), blurRadius: 4, offset: const Offset(0, 2), ), ], ), child: Row( mainAxisAlignment: MainAxisAlignment.center, children: [ AnimatedContainer( duration: const Duration(milliseconds: 300), width: 16, height: 16, decoration: BoxDecoration( shape: BoxShape.circle, border: Border.all( color: _selectedGender == 'FEMALE' ? const Color(0xFF5B259F) : Colors.grey.shade300, width: 2, ), color: _selectedGender == 'FEMALE' ? const Color(0xFF5B259F) : Colors.white, ), child: _selectedGender == 'FEMALE' ? const Icon( Icons.check, size: 12, color: Colors.white, ) : null, ), const SizedBox(width: 12), Row( children: [ Icon( Icons.female, color: _selectedGender == 'FEMALE' ? const Color(0xFF5B259F) : Colors.grey.shade500, size: 16, ), const SizedBox(width: 6), Txt( text:'FEMALE', style: TextStyle( fontFamily: 'Poppins', fontSize: 16, fontWeight: _selectedGender == 'FEMALE' ? FontWeight.w600 : FontWeight.w500, color: _selectedGender == 'FEMALE' ? const Color(0xFF5B259F) : Colors.grey.shade500, ), ), ], ), ], ), ), ), ); }, ), ), ], ), ); } }