opt: search TextField suffix
This commit is contained in:
@ -50,28 +50,10 @@ class _SearchPageState extends State<SearchPage> with RouteAware {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
actions: [
|
actions: [
|
||||||
IconButton(
|
Obx(() {
|
||||||
onPressed: () => _searchController.submit(),
|
|
||||||
icon: const Icon(Icons.search),
|
|
||||||
),
|
|
||||||
const SizedBox(width: 10)
|
|
||||||
],
|
|
||||||
title: Obx(
|
|
||||||
() => TextField(
|
|
||||||
autofocus: true,
|
|
||||||
focusNode: _searchController.searchFocusNode,
|
|
||||||
controller: _searchController.controller.value,
|
|
||||||
textInputAction: TextInputAction.search,
|
|
||||||
onChanged: _searchController.onChange,
|
|
||||||
decoration: InputDecoration(
|
|
||||||
hintText: _searchController.hintText,
|
|
||||||
border: InputBorder.none,
|
|
||||||
suffix: Obx(() {
|
|
||||||
RxString searchKeyWord = _searchController.searchKeyWord;
|
RxString searchKeyWord = _searchController.searchKeyWord;
|
||||||
if (searchKeyWord.value.isEmpty) {
|
return searchKeyWord.value.isNotEmpty
|
||||||
return const SizedBox();
|
? Row(
|
||||||
}
|
|
||||||
return Row(
|
|
||||||
mainAxisSize: MainAxisSize.min,
|
mainAxisSize: MainAxisSize.min,
|
||||||
children: [
|
children: [
|
||||||
if (RegExp(r'^\d+$').hasMatch(searchKeyWord.value))
|
if (RegExp(r'^\d+$').hasMatch(searchKeyWord.value))
|
||||||
@ -86,11 +68,28 @@ class _SearchPageState extends State<SearchPage> with RouteAware {
|
|||||||
),
|
),
|
||||||
IconButton(
|
IconButton(
|
||||||
icon: const Icon(Icons.clear, size: 22),
|
icon: const Icon(Icons.clear, size: 22),
|
||||||
onPressed: () => _searchController.onClear(),
|
onPressed: _searchController.onClear,
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
);
|
)
|
||||||
|
: const SizedBox();
|
||||||
}),
|
}),
|
||||||
|
IconButton(
|
||||||
|
onPressed: _searchController.submit,
|
||||||
|
icon: const Icon(Icons.search),
|
||||||
|
),
|
||||||
|
const SizedBox(width: 10)
|
||||||
|
],
|
||||||
|
title: Obx(
|
||||||
|
() => TextField(
|
||||||
|
autofocus: true,
|
||||||
|
focusNode: _searchController.searchFocusNode,
|
||||||
|
controller: _searchController.controller.value,
|
||||||
|
textInputAction: TextInputAction.search,
|
||||||
|
onChanged: _searchController.onChange,
|
||||||
|
decoration: InputDecoration(
|
||||||
|
hintText: _searchController.hintText,
|
||||||
|
border: InputBorder.none,
|
||||||
),
|
),
|
||||||
onSubmitted: (String value) => _searchController.submit(),
|
onSubmitted: (String value) => _searchController.submit(),
|
||||||
),
|
),
|
||||||
|
|||||||
Reference in New Issue
Block a user