这是我的搜索代码,当我搜索和显示列表视图,我怎么能希望在完成搜索后获取列表视图以外的文本表单字段?
我在搜索框中输入了一些文本,数据被成功提取。但是我希望列表视图外的文本字段在搜索后有文本,我该怎么做?我正在练习
onSearch(String text) async {
if (text.isNotEmpty) {
List<Item> itemList = [];
for (var item in items) {
if (item.custnum == text.toString().toLowerCase().toUpperCase()) {
itemList.add(item);
setState(() {
searchitems.clear();
searchitems.addAll(itemList);
print('name : ${searchitems[0].name}');
if (searchitems.isEmpty) {
searchitems = [];
// print('searchitems : ${searchitems[0].address!.length}');
// print('searchitems : ${searchitems[0].address!}');
}
});
}
}
} else {
setState(() {
searchitems.clear();
// searchitems.addAll(items);
print('searchitems : $searchitems');
});
}
这是文本表单字段
TextFormField(
decoration: InputDecoration(
labelText: 'name',
labelStyle: TextStyle(
fontFamily: 'supermarket', fontSize: 14),
isDense: true,
),
),
这是列表视图
child: searchitems.isNotEmpty
? ListView.builder(
controller: controllerlistview,
itemCount: searchitems[0].address!.length,
itemBuilder: (context, index) {
return InkWell(
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: ((context) => EditAddressPage(
custaddr:
searchitems[0].address![0]))));
},
child: Card(
elevation: 3,
child: Column(
children: <Widget>[
Padding(
padding: const EdgeInsets.all(10.0),
child: Row(
mainAxisAlignment:
MainAxisAlignment.end,
children: <Widget>[
Text(
'แก้ไข${searchitems[0].name}',
style: TextStyle(
fontFamily: "supermarket",
fontSize: 14,
color: Colors.lightBlue),
),
],
),
),
Padding(
padding: const EdgeInsets.all(5),
child: Row(
mainAxisAlignment:
MainAxisAlignment.start,
children: [
Text(
'bill To / Ship To : ${searchitems[0].address![index].shipto.toString()}',
style: TextStyle(
color: Colors.black,
fontSize: 16,
fontFamily: "supermarket"),
),
],
),
),
Padding(
padding: const EdgeInsets.all(5),
child: Row(
mainAxisAlignment:
MainAxisAlignment.start,
children: [
Text(
"ที่อยู่ : ${searchitems[0].address![index].addr1.toString()}",
style: TextStyle(
color: Colors.black,
fontSize: 16,
fontFamily: "supermarket"),
),
],
),
),
],
),
),
);
})
: Center(child: Text('ไม่มีข้อมูล'))),
1条答案
按热度按时间7rfyedvj1#