【发布时间】:2021-05-06 15:31:42
【问题描述】:
我实施了一个搜索列表,并咨询了 Firebase。最初,所有注册用户都出现在屏幕上,当我单击其中一个用户时,应用程序会显示另一个屏幕,其中包含该用户的所有数据。当您开始在搜索字段中输入内容时,只会显示与输入文本相关的用户。
但是,出现了一个问题:过滤客户时,只有它出现在屏幕上,当我点击打开客户信息时,应用程序会在总列表中显示第一个用户的信息(不考虑过滤器) )。
我相信这是由于索引,它查看文档在 firebase 中的位置。
如何解决这个问题?谢谢!
body: Column(
children: <Widget>[
SizedBox(
height: 5,
),
TextField(
controller: _procurarpaciente,
decoration: InputDecoration(
border: OutlineInputBorder(), labelText: "Pesquisar paciente",prefixIcon: Icon(Icons.search)
),
onChanged: (val) {
setState(() {
nome = val;
});
},
),
Expanded(
child: StreamBuilder<QuerySnapshot>(
stream: (nome != "" && nome != null)
? Firestore.instance
.collection('pacientes')
.where("indexList", arrayContains: nome)
.snapshots()
: Firestore.instance.collection("pacientes").snapshots(),
builder: (context, snapshot) {
switch(snapshot.connectionState){
case ConnectionState.none:
case ConnectionState.waiting:
return Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Icon(Icons.error_outline),
Text("Usuário não encontrado")
],
),
);
default:
// List<DocumentSnapshot> documentos =
// snapshot.data.documents;
return ListView.builder(
itemCount: snapshot.data.documents.length,
itemBuilder: (context, index) {
DocumentSnapshot data = snapshot.data.documents[index];
return ListTile(
title: Text(
data['nome'],
style: TextStyle(
fontWeight: FontWeight.w700,
fontSize: 16,
),),
subtitle:Text(
"Quarto: ${data['quarto']}",
style: TextStyle(
fontWeight: FontWeight.w700,
fontSize: 14,
),),
leading:CircleAvatar(
backgroundImage: NetworkImage(data['foto']),
),
onTap: ()=> {
//print(data.documentID),
_navegarParaPerfil(context, items[index]),
}
);
},
);
}
}
),
)
],
),
void _navegarParaPerfil(BuildContext context, Paciente paciente) async{
await Navigator.push(context,
MaterialPageRoute(builder: (context) => TelaPaciente(paciente)),
);
}
dsdsd
【问题讨论】:
-
_navegarParaPerfil(context, items[index]) --> items 表示 ?
-
当我按下所选用户时,我调用类 _navegarParaPerfil(导航到配置文件),将索引作为参数传递
-
@BalasubramaniSundaram 这个类,打开一个包含所选配置文件信息的屏幕
-
做完过滤,有没有刷新items collection
-
@BalasubramaniSundaram 我尝试这样做,但即使在列表中显示正确的用户,当点击它时,过滤器也不会应用,并且总是打开列表中的第一个没有过滤器的用户跨度>
标签: list firebase flutter search google-cloud-firestore