У меня есть форма с текстовым полем, в которой должно быть имя доктора, при щелчке он вызывает ShowSearch () для поиска имени доктора
Я реализовал почти все, что я не могу сделать, это когда пользователь щелкает одно из предложений, я хочу, чтобы это предложение (один текст) вернулось go в текстовое поле в предыдущем виджете.
my TextField:
TextFormField (
onTap: (){showSearch(context: context, delegate: DataSearch());},
style: TextStyle(
color: Colors.white,
fontWeight: FontWeight.w600),
decoration: new InputDecoration(
enabledBorder: OutlineInputBorder(
borderSide: const BorderSide(
color: Colors.white, width: 2.0),
borderRadius:
BorderRadius.circular(8.0),
),
labelText: "Doctor name",
labelStyle: MyFontStyles.textFieldsLabelStyle(context),
),
),
Мой ShowSearch ():
class DataSearch extends SearchDelegate<String> {
@override
List<Widget> buildActions(BuildContext context) {
return [IconButton(icon:Icon(Icons.clear),onPressed: (){query
="";},)];
}
@override
Widget buildLeading(BuildContext context) {
return IconButton(
icon: AnimatedIcon(
icon: AnimatedIcons.menu_arrow,
progress: transitionAnimation,
),
onPressed: () {close(context, "search result");},
);
}
@override
Widget buildResults(BuildContext context) {
// TODO: implement buildResults
throw UnimplementedError();
}
// ! CALLS SYNC FUNCTIONS WITHOUT AWAIT !
@override
Widget buildSuggestions(BuildContext context) {
DoctorsController.fetchAllDoctors();
List doctorsList = DoctorsController.getDoctorsNamesAsList();
final List<String>suggestionList =query.isEmpty? doctorsList :
doctorsList.where((element) => element.contains(query)).toList();
return ListView.builder(
itemBuilder: (context, index) {
String sugText = suggestionList[index];
return ListTile(
title:
RichText(
text: TextSpan(
text:sugText.substring(0, sugText.indexOf(query)),
style:
TextStyle(color: Colors.grey),
children: [
TextSpan(
text: sugText.substring(sugText.indexOf(query), sugText.indexOf(query)+query.length),
style: TextStyle(color: Colors.black,fontWeight: FontWeight.bold),
),TextSpan(
text: sugText.substring(sugText.indexOf(query)+query.length, sugText.length),
style: TextStyle(color: Colors.grey),
)
],
),
)
);},
itemCount: suggestionList.length,
);
}
}