我有以下代码,我正在模拟器(ios)的联系人中搜索,但在真实设备(iphone)上无法正常工作(仅过滤不起作用)
我尝试了两种不同的方法来制作它,但在实际设备上不起作用,我尝试使用以下代码和自动完成文本字段pacakge
任何想法
void filterContacts(String query) {
print(query);
setState(() {
isSearching = true;
});
if (query == "" || query == null){
setState(() {
isSearching = false;
contactsName.clear();
contactsName = filterName;
});
print("reset");
print(isSearching);
}
setState(() {
contactsName = contactsName.where((name) =>
name.toLowerCase().contains(query.toLowerCase())
)
.toList();
print("contactsName");
});
}
...
TextField(
controller: _contactController,
decoration: InputDecoration(
hintText: "Contact",
suffixIcon: IconButton(
onPressed: () {
_contactController.clear();
FocusScope.of(context).unfocus();
setState(() {
isSearching = false;
contactsName = filterName;
});
},
icon: Icon(Icons.clear),
),
),
textInputAction: TextInputAction.search,
onChanged: (value) {
filterContacts(value);
},
),
...
isSearching ?
Expanded(
//padding: const EdgeInsets.only(left:80.0,bottom: 500),
//padding: const EdgeInsets.symmetric(),
child: ListView.builder(
itemCount: contactsName.length,
shrinkWrap: true,
itemBuilder: (BuildContext context, int index) {
return ListTile(
title: InkWell(
child: Text(contactsName[index]?? ""),
onTap: (){
setState(() {
_contactController.text = contactsName[index];
isSearching = false;
contactsName.clear();
contactsName = filterName;
});
print(index);
var position = filterName.indexOf(contactsName[index]);
//contactsList[i].phones.elementAt(j).value
print(contactNumbers[position]);
},
)
);
},
),