【发布时间】:2021-05-07 14:32:48
【问题描述】:
我正在使用这个包:https://pub.dev/packages/material_floating_search_bar/example
我不想在操作中使用 .searchToClear() 方法。
我想添加我的自定义图标,所以我试图在调用 onPressed 时清除搜索栏。但我明白了:
The following NoSuchMethodError was thrown while handling a gesture:
The method 'clear' was called on null.
Receiver: null
Tried calling: clear()
这是我的代码
_searchBar() {
return FloatingSearchBar(
backdropColor: Colors.transparent,
hint: 'Search...',
scrollPadding: const EdgeInsets.only(top: 16, bottom: 56),
transitionDuration: const Duration(milliseconds: 800),
transitionCurve: Curves.easeInOut,
physics: const BouncingScrollPhysics(),
openAxisAlignment: 0.0,
debounceDelay: const Duration(milliseconds: 500),
onQueryChanged: (query) {
// Call your model, bloc, controller here.
},
// Specify a custom transition to be used for
// animating between opened and closed stated.
transition: CircularFloatingSearchBarTransition(),
actions: [
// FloatingSearchBarAction.searchToClear(
// showIfClosed: false,
// ),
FloatingSearchBarAction.icon(
showIfClosed: false,
showIfOpened: true,
icon: Icon(Icons.clear),
onTap: () {
final bar = FloatingSearchAppBar.of(context);
bar.clear();
print(bar);
}),
],
builder: (context, transition) {
return ClipRRect(
borderRadius: BorderRadius.circular(8),
child: Material(
color: Colors.white,
elevation: 4.0,
child: Column(
mainAxisSize: MainAxisSize.min,
children: Colors.accents.map((color) {
return Container(height: 112, color: color);
}).toList(),
),
),
);
},
);
}
【问题讨论】:
标签: android flutter dart searchbar