This is my search code when i search and show listview how can i want the textformfield outside listview to fetch after complete search?
I typed some text into the search box and the data was fetched successfully. But I want the textfield outside the listview to have text after search, what should I do? i am practicing
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');
});
}
This is TextFormField
TextFormField(
decoration: InputDecoration(
labelText: 'name',
labelStyle: TextStyle(
fontFamily: 'supermarket', fontSize: 14),
isDense: true,
),
),
This is listview
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('ไม่มีข้อมูล'))),
Just assign this to your TextFormField and you can get the search box value from it.
final textController=TextEditingController();
TextFormField(
decoration: InputDecoration(
labelText: 'name',
labelStyle: TextStyle(
fontFamily: 'supermarket', fontSize: 14),
isDense: true,
),
controller: textController,
),
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.