@@ -49,7 +49,7 @@ class _NewChatPageState extends State<NewChatPage> {
4949 autofocus: true ,
5050 style: const TextStyle (color: Colors .black87),
5151 decoration: const InputDecoration (
52- hintText: "Enter exact username ..." ,
52+ hintText: "Enter minimum 3 characters ..." ,
5353 hintStyle: TextStyle (color: Colors .black38),
5454 enabledBorder: UnderlineInputBorder (
5555 borderSide: BorderSide (color: Colors .black26),
@@ -73,13 +73,22 @@ class _NewChatPageState extends State<NewChatPage> {
7373 ),
7474 onPressed: () {
7575 final text = inputController.text.trim ();
76- if (text.isNotEmpty ) {
76+ if (text.length >= 3 ) {
7777 context.read <ChatController >().queryUsers (text);
7878 setState (() {
7979 _searchController.text = text;
8080 });
81+ Navigator .pop (context);
82+ } else {
83+ ScaffoldMessenger .of (context).showSnackBar (
84+ const SnackBar (
85+ content: Text (
86+ "Search query must be at least 3 characters." ,
87+ ),
88+ backgroundColor: Colors .redAccent,
89+ ),
90+ );
8191 }
82- Navigator .pop (context);
8392 },
8493 child: const Text ("Search" , style: TextStyle (color: Colors .white)),
8594 ),
@@ -115,7 +124,9 @@ class _NewChatPageState extends State<NewChatPage> {
115124 @override
116125 Widget build (BuildContext context) {
117126 final chatState = context.watch <ChatController >();
118- final bool isSearching = _searchController.text.trim ().isNotEmpty;
127+ final String searchInput = _searchController.text.trim ();
128+ final bool isSearching = searchInput.isNotEmpty;
129+ final bool hasValidQueryLength = searchInput.length >= 3 ;
119130
120131 return Scaffold (
121132 backgroundColor: Colors .white,
@@ -172,7 +183,17 @@ class _NewChatPageState extends State<NewChatPage> {
172183 ),
173184 Expanded (
174185 child: isSearching
175- ? (chatState.isSearchLoading
186+ ? (! hasValidQueryLength
187+ ? const Center (
188+ child: Text (
189+ "Type at least 3 characters to search..." ,
190+ style: TextStyle (
191+ color: Colors .black45,
192+ fontSize: 14 ,
193+ ),
194+ ),
195+ )
196+ : chatState.isSearchLoading
176197 ? const Center (
177198 child: CircularProgressIndicator (
178199 color: Color (0xFF1890FF ),
0 commit comments