提问人:Saurabh Jain 提问时间:9/14/2023 更新时间:9/14/2023 访问量:21
TypeAheadField:如何处理 TypeAheadField 中的小拼写错误
TypeAheadField: How to handle minor misspellings in TypeAheadField
问:
这就是我实现的方式,这与其中键入的确切拼写一起工作正常。TypeAheadField
TypeAheadField(
noItemsFoundBuilder: (context) => const SizedBox(
height: 50,
child: Center(child: Text("No user found!")),
),
suggestionsBoxDecoration: SuggestionsBoxDecoration(
color: Colors.deepPurple.shade50,
elevation: 3.0,
borderRadius: const BorderRadius.only(
topLeft: Radius.circular(15),
topRight: Radius.circular(15),
bottomLeft: Radius.circular(15),
bottomRight: Radius.circular(15))),
textFieldConfiguration: TextFieldConfiguration(
// Use inputFormatters to restrict input to alphabetic characters.
inputFormatters: [
FilteringTextInputFormatter.allow(RegExp(r'[a-zA-Z]')),
],
controller: _allLeaveViewModel.searchController,
onChanged: (value) {
_allLeaveViewModel.isSearchTextNotEmpty.value =value.isNotEmpty;
//_allLeaveViewModel.updateList(value);
// if (value.isEmpty) {
// Utils.removeFocusFromSearch(context);
// }
},
decoration: InputDecoration(
contentPadding: const EdgeInsets.fromLTRB(
16.0, 12.0, 16.0, 12.0),
hintText: 'Filter by applicant...',
hintStyle: TextStyle(
color: Colors.black.withOpacity(0.5),
fontSize: 16),
filled: true,
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(70),
borderSide: BorderSide.none,
),
suffixIcon: Obx(() {
return Visibility(
visible: _allLeaveViewModel
.isSearchTextNotEmpty.value,
child: IconButton(
icon: Icon(
Icons.cancel_outlined,
color: Colors.grey.shade700,
size: 25,
),
onPressed: () {
_allLeaveViewModel.clearSearchAndList();
},
),
);
}),
),
),
suggestionsCallback: (pattern) async {
return _allLeaveViewModel.getSuggestions(pattern);
},
minCharsForSuggestions: 2,
itemBuilder:
(BuildContext context, String suggestion) {
return Padding(
padding: const EdgeInsets.symmetric(vertical: 10),
child: Row(
children: [
const SizedBox(
width: 10,
),
Flexible(
child: Text(
suggestion,
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: const TextStyle(fontSize: 16),
))
],
),
);
},
onSuggestionSelected: (suggestion) {
_allLeaveViewModel.isSearchTextNotEmpty.valuesuggestion.isNotEmpty;
_allLeaveViewModel.searchController.text = suggestion;
_allLeaveViewModel.updateList(suggestion);
},
)
但是我无法找到如何处理其中输入的轻微拼写错误, 谁能帮我?
答:
评论