import 'package:wanisdriver/Provider/language_provider.dart'; import 'package:flutter/material.dart'; import '../utils/colors.dart'; import 'custom_text.dart'; class FullScreenDropdownModal extends StatefulWidget { final String label; final List items; final String? selectedItem; final String Function(T) getItemLabel; final Function(String?) onSelect; const FullScreenDropdownModal({ required this.label, required this.items, required this.selectedItem, required this.getItemLabel, required this.onSelect, }); @override State> createState() => FullScreenDropdownModalState(); } class FullScreenDropdownModalState extends State> { final TextEditingController _searchController = TextEditingController(); List _filteredItems = []; @override void initState() { super.initState(); _filteredItems = widget.items; _searchController.addListener(_filterItems); } @override void dispose() { _searchController.dispose(); super.dispose(); } void _filterItems() { final query = _searchController.text.toLowerCase(); setState(() { if (query.isEmpty) { _filteredItems = widget.items; } else { _filteredItems = widget.items .where((item) => widget.getItemLabel(item).toLowerCase().contains(query)) .toList(); } }); } @override Widget build(BuildContext context) { final isDarkMode = Theme.of(context).brightness == Brightness.dark; final theme = Theme.of(context); final Color activeColor = theme.primaryColor; return Container( height: MediaQuery.of(context).size.height * 0.9, decoration: BoxDecoration( color: isDarkMode ? AppColors.blackBackgroundColor : AppColors.whiteBackgroundColor, borderRadius: const BorderRadius.only( topLeft: Radius.circular(25), topRight: Radius.circular(25), ), ), child: Column( children: [ // Header Container( padding: const EdgeInsets.all(20), decoration: BoxDecoration( color: isDarkMode ? AppColors.blackBackgroundColor : AppColors.whiteBackgroundColor, borderRadius: const BorderRadius.only( topLeft: Radius.circular(25), topRight: Radius.circular(25), ), boxShadow: [ BoxShadow( color: Colors.black.withOpacity(0.05), blurRadius: 4, offset: const Offset(0, 2), ), ], ), child: Column( children: [ // Drag handle Container( width: 40, height: 4, decoration: BoxDecoration( color: Colors.grey.shade300, borderRadius: BorderRadius.circular(2), ), ), const SizedBox(height: 20), // Title Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ Txt( text: languageSingleton.translate(widget.label), style: TextStyle( fontSize: 18, fontWeight: FontWeight.w600, fontFamily: 'Poppins', color: isDarkMode ? AppColors.white : AppColors.black, ), ), IconButton( icon: Icon( Icons.close, color: isDarkMode ? AppColors.white : AppColors.black, ), onPressed: () => Navigator.pop(context), ), ], ), const SizedBox(height: 15), // Search Field TextField( controller: _searchController, style: TextStyle( fontFamily: 'Poppins', fontSize: 16, color: isDarkMode ? AppColors.white : AppColors.black, ), decoration: InputDecoration( hintText: languageSingleton.translate('Search...'), hintStyle: TextStyle( fontFamily: 'Poppins', fontSize: 14, color: isDarkMode ? AppColors.darkSecondaryText.withOpacity(0.5) : Colors.grey.shade400, ), prefixIcon: Icon( Icons.search, color: isDarkMode ? AppColors.darkSecondaryText : Colors.grey.shade600, ), suffixIcon: _searchController.text.isNotEmpty ? IconButton( icon: Icon( Icons.clear, color: isDarkMode ? AppColors.darkSecondaryText : Colors.grey.shade600, ), onPressed: () { _searchController.clear(); }, ) : null, filled: true, fillColor: isDarkMode ? Colors.grey.shade800 : Colors.grey.shade100, border: OutlineInputBorder( borderRadius: BorderRadius.circular(15), borderSide: BorderSide.none, ), contentPadding: const EdgeInsets.symmetric(horizontal: 16, vertical: 12), ), ), ], ), ), // List Expanded( child: _filteredItems.isEmpty ? Center( child: Txt( text: languageSingleton.translate('No results found'), style: TextStyle( fontSize: 14, fontFamily: 'Poppins', color: isDarkMode ? AppColors.darkSecondaryText : Colors.grey.shade600, ), ), ) : ListView.builder( padding: const EdgeInsets.symmetric(vertical: 10), itemCount: _filteredItems.length, itemBuilder: (context, index) { final item = _filteredItems[index]; final label = widget.getItemLabel(item); final isSelected = label == widget.selectedItem; return InkWell( onTap: () { widget.onSelect(label); Navigator.pop(context); }, child: Container( padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 16), decoration: BoxDecoration( color: isSelected ? activeColor.withOpacity(0.1) : Colors.transparent, border: Border( bottom: BorderSide( color: isDarkMode ? Colors.grey.shade800 : Colors.grey.shade200, width: 0.5, ), ), ), child: Row( children: [ Expanded( child: Text( label, style: TextStyle( fontFamily: 'Poppins', fontSize: 16, fontWeight: isSelected ? FontWeight.w600 : FontWeight.w400, color: isSelected ? activeColor : isDarkMode ? AppColors.white : AppColors.black, ), ), ), if (isSelected) Icon( Icons.check_circle, color: activeColor, size: 22, ), ], ), ), ); }, ), ), ], ), ); } }