diff --git a/dialer/lib/features/home/home_page.dart b/dialer/lib/features/home/home_page.dart index ae333e6..f4f2d6b 100644 --- a/dialer/lib/features/home/home_page.dart +++ b/dialer/lib/features/home/home_page.dart @@ -18,6 +18,7 @@ class _MyHomePageState extends State with SingleTickerProviderStateM final ObfuscateService _obfuscateService = ObfuscateService(); final TextEditingController _searchController = TextEditingController(); late SearchController _searchBarController; + String _rawSearchInput = ''; @override void initState() { @@ -26,9 +27,9 @@ class _MyHomePageState extends State with SingleTickerProviderStateM _tabController.addListener(_handleTabIndex); _searchBarController = SearchController(); _searchBarController.addListener(() { - // Sync _searchController with SearchController in real-time if (_searchController.text != _searchBarController.text) { - _searchController.text = _searchBarController.text; + _rawSearchInput = _searchBarController.text; + _searchController.text = _rawSearchInput; _onSearchChanged(_searchBarController.text); } }); @@ -44,6 +45,7 @@ class _MyHomePageState extends State with SingleTickerProviderStateM void _clearSearch() { _searchController.clear(); _searchBarController.clear(); + _rawSearchInput = ''; _onSearchChanged(''); } @@ -162,14 +164,14 @@ class _MyHomePageState extends State with SingleTickerProviderStateM const SizedBox(width: 8.0), Expanded( child: Text( - _searchController.text.isEmpty + _rawSearchInput.isEmpty ? 'Search contacts' - : _searchController.text, + : _rawSearchInput, style: const TextStyle(color: Colors.grey, fontSize: 16.0), overflow: TextOverflow.ellipsis, ), ), - if (_searchController.text.isNotEmpty) + if (_rawSearchInput.isNotEmpty) GestureDetector( onTap: _clearSearch, child: const Icon( @@ -184,9 +186,11 @@ class _MyHomePageState extends State with SingleTickerProviderStateM ); }, viewOnChanged: (query) { - // Update immediately as you type + if (_searchBarController.text != query) { + _rawSearchInput = query; _searchBarController.text = query; + _searchController.text = query; } _onSearchChanged(query); },