【发布时间】:2021-06-10 08:02:27
【问题描述】:
我创建了一个列表视图,该列表视图由从 Web 服务接收到的 JSON 字符串填充。 我想根据插入到 textField 小部件中的搜索字符串过滤数据。
这个未来接收到的json字符串:
future: fetchPacientes(value)
我应该如何根据插入到 textField 中的字符串从 snapShot 中获取过滤后的值?
body: Padding(
padding: const EdgeInsets.all(8.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Center(
child: Text(
'Patients'.tr().toString(),
style: TextStyle(fontSize: 24.0, color: Colors.black45),
),
),
SizedBox(
height: 8,
),
// in the build method above list
TextField(
decoration: InputDecoration(
contentPadding: EdgeInsets.all(15.0),
hintText: 'Filter by name or NHC',
),
onChanged: (string) {
print("filtering string->:"+ string);
},
),
Expanded(
child: Consumer(
builder: (context, watch, child) {
var value = watch(clinicaIdStateProvider).state;
return Container(
child: FutureBuilder(
future: fetchPacientes(value),
builder: (context, snapshot) {
if (snapshot.hasData) {
return ListView.builder(
itemCount: snapshot.data.length,
shrinkWrap: true,
itemBuilder: (BuildContext context, index) {
Paciente paciente = snapshot.data[index];
return new GestureDetector(
onTap: () {
print("paciente seleccionada nbre: " +
'${paciente.nombre_completo}');
},
child: new Card(
elevation: 6,
child: new Container(
child: Column(
children: [
Padding(
padding: const EdgeInsets.all(8.0),
child: Row(
mainAxisAlignment:
MainAxisAlignment.spaceBetween,
children: [
Padding(
padding:
const EdgeInsets.all(8.0),
child: Text(
"${paciente.apellidos}" +
", " +
"${paciente.nombre_completo}",
style:
TextStyle(fontSize: 18),
),
),
Column(
children: [
Container(
decoration: BoxDecoration(
color:
AppColors.azulCapenergy,
border: Border.all(
color: AppColors
.azulCapenergy,
),
borderRadius:
BorderRadius.all(
Radius.circular(
20))),
child: Padding(
padding:
const EdgeInsets.all(8.0),
child: Text(
"NHC: ${paciente.NHC}",
style: TextStyle(
color: AppColors
.blancoCapenergy,
fontSize: 16),
),
),
),
SizedBox(height: 3,),
FlatButton(
onPressed: (){
print("boton agenda pulsado de ${paciente.nombre_completo}");
},
child: Container(
decoration: BoxDecoration(
color:
Colors.transparent,
border: Border.all(
color: AppColors
.azulCapenergy,
),
borderRadius:
BorderRadius.all(
Radius.circular(
15))),
child: Padding(
padding:
const EdgeInsets.all(8.0),
child: Image.network(
'https://...iconos_app/agenda.png',
height: 25,
),
),
),
),
],
),
],
),
),
],
),
),
),
);
},
);
}
return Image.asset(
"assets/images/vacio.png",
fit: BoxFit.contain,
);
},
),
);
},
),
),
],
),
),
【问题讨论】:
标签: flutter