이것은 클라우드 파이어 스토어의 사용자 컬렉션입니다.
이것은 firestore의 사용자 컬렉션에서 사용자를 가져 오는 함수입니다.
Stream<QuerySnapshot> fetchUsersInSearch() {
return Firestore.instance.collection('users').snapshots();
}
나는이 방법을 사용한다
final emailResults = snapshot.data.documents
.where((u) => u['email'].contains(query));
다음 streamBuilder에서 이메일로 사용자를 가져옵니다.
화면에 데이터를 채우는이 streamBuilder가 있습니다.
return StreamBuilder<QuerySnapshot>(
stream: DatabaseService().fetchUsersInSearch(),
builder: (context, AsyncSnapshot<QuerySnapshot> snapshot) {
final emailResults = snapshot.data.documents
.where((u) => u['email'].contains(query));
if (!snapshot.hasData) {
return Container(
color: Theme.of(context).primaryColor,
child: Center(
child: Text(
'',
style: TextStyle(
fontSize: 16, color: Theme.of(context).primaryColor),
),
),
);
}
if (emailResults.length > 0) {
return Container(
color: Theme.of(context).primaryColor,
child: ListView(
children: emailResults
.map<Widget>((u) => GestureDetector(
child: Padding(
padding: const EdgeInsets.all(0.1),
child: Container(
padding: EdgeInsets.symmetric(vertical: 5),
decoration: BoxDecoration(
color: Theme.of(context).primaryColor,
border: Border(
bottom: BorderSide(
width: 0.3, color: Colors.grey[50]))),
child: ListTile(
leading: CircleAvatar(
backgroundColor:
Theme.of(context).primaryColor,
backgroundImage:
NetworkImage(u['userAvatarUrl']),
radius: 20,
),
title: Container(
padding: EdgeInsets.only(left: 10),
child: Column(
crossAxisAlignment:
CrossAxisAlignment.start,
children: [
Text(u['email'],
style: TextStyle(
fontSize: 16,
color: Theme.of(context)
.accentColor),
overflow: TextOverflow.ellipsis),
SizedBox(
height: 5,
),
],
),
),
),
),
),
onTap: () {
showUserProfile(u['id']);
},
))
.toList(),
),
);
} else {
return Container(
color: Theme.of(context).primaryColor,
child: Center(
child: Text(
'No results found',
style: TextStyle(
fontSize: 16,
color: Theme.of(context).accentColor,
),
),
),
);
}
});
이것은 완벽하게 작동하고 이메일로 listView 내에서 사용자를 가져옵니다 ...
추신 : (쿼리)는 검색 막대에 입력 한 문자열입니다.
otherUsernames ... users 컬렉션 스크린 샷의 두 번째 필드로 사용자를 가져 오는 쿼리를 어떻게 만들 수 있습니까?!
나는 이것을 시도했다 :
final otherUsernamesResults = snapshot.data.documents
.where((u) => u['otherUsernames'].contains(query));
그러나이 오류를 반환합니다.
The method 'contains' was called on null.
Receiver: null
Tried calling: contains("#username1")
내가 여기서 뭘 잘못하고 있니? !!
어떤 도움을 주시면 감사하겠습니다 ..
이 시도:-
Stream<QuerySnapshot> getUsers() {
final usersCollection = FirebaseFirestore.instance.collection('users');
return usersCollection.where('otherUsernames', arrayContainsAny: ['username1', 'username2']);
}
Firestore 버전 0.16.0의 경우
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다