@@ -110,52 +110,72 @@ class _HomeScreenState extends State<HomeScreen> {
110110 //Floating Button Icon to add new user
111111 floatingActionButton: Padding (
112112 padding: const EdgeInsets .only (bottom: 35 ),
113- child: FloatingActionButton (onPressed: () async {
114- // _addChatUserDialog();
113+ child: FloatingActionButton (onPressed: () {
114+ _addChatUserDialog ();
115115 },
116116 child: const Icon (Icons .add_circle_outline),
117117 ),
118118 ),
119119
120120 body: StreamBuilder (
121- stream: APIs .getAllUsers (),
122- builder: (context, snapshot) {
121+ stream: APIs .getMyUserId (),
123122
124- switch (snapshot.connectionState){
125- // If Data is Loading
123+ //get id of only known users
124+ builder: (context, snapshot) {
125+ switch (snapshot.connectionState) {
126+ //if data is loading
126127 case ConnectionState .waiting:
127128 case ConnectionState .none:
128- return const Center (child: CircularProgressIndicator (), );
129+ return const Center (child: CircularProgressIndicator ());
129130
130- // If some or all Data is loaded then show it
131+ //if some or all data is loaded then show it
131132 case ConnectionState .active:
132133 case ConnectionState .done:
133-
134-
135- final data = snapshot.data? .docs;
136- _list = data? .map ((e) => ChatUser .fromJson (e.data ())).toList () ?? [];
137-
138- if (_list.isNotEmpty){
139- return ListView .builder (
140- itemCount: _isSearching ? _searchList.length : _list.length,
141- padding: EdgeInsets .only (top: mq.height * .01 ),
142- physics: const BouncingScrollPhysics (),
143- itemBuilder: (context, index){
144- return ChatUserCard (
145- user: _isSearching ? _searchList[index] : _list[index],);
146- // return Text('Name: ${list[index]}');
147- });
148- }else {
149- return const Center (
150- child: Text ('No Connections Found!' ,
151- style: TextStyle (
152- fontSize: 20 ,
153- ),),
134+ return StreamBuilder (
135+ stream: APIs .getAllUsers (
136+ snapshot.data? .docs.map ((e) => e.id).toList () ?? []),
137+
138+ //get only those user, who's ids are provided
139+ builder: (context, snapshot) {
140+ switch (snapshot.connectionState) {
141+ //if data is loading
142+ case ConnectionState .waiting:
143+ case ConnectionState .none:
144+ // return const Center(
145+ // child: CircularProgressIndicator());
146+
147+ //if some or all data is loaded then show it
148+ case ConnectionState .active:
149+ case ConnectionState .done:
150+ final data = snapshot.data? .docs;
151+ _list = data
152+ ? .map ((e) => ChatUser .fromJson (e.data ()))
153+ .toList () ??
154+ [];
155+
156+ if (_list.isNotEmpty) {
157+ return ListView .builder (
158+ itemCount: _isSearching
159+ ? _searchList.length
160+ : _list.length,
161+ padding: EdgeInsets .only (top: mq.height * .01 ),
162+ physics: const BouncingScrollPhysics (),
163+ itemBuilder: (context, index) {
164+ return ChatUserCard (
165+ user: _isSearching
166+ ? _searchList[index]
167+ : _list[index]);
168+ });
169+ } else {
170+ return const Center (
171+ child: Text ('No Connections Found!' ,
172+ style: TextStyle (fontSize: 20 )),
173+ );
174+ }
175+ }
176+ },
154177 );
155- }
156178 }
157-
158-
159179 },
160180 ),
161181 ),
@@ -184,7 +204,7 @@ class _HomeScreenState extends State<HomeScreen> {
184204 color: Colors .deepOrange,
185205 size: 28 ,
186206 ),
187- Text (' Add User' )
207+ Text (' Add User' )
188208 ],
189209 ),
190210
0 commit comments