gpt4 book ai didi

dart - flutter_search_bar 插件 onClose 监听器

转载 作者:IT王子 更新时间:2023-10-29 06:54:57 25 4
gpt4 key购买 nike

我目前正在使用带标签页的 flutter_search_bar 插件。因为我的值(value)观是动态变化的。我想知道是否有任何方法可以将监听器添加到包中以进行必要的更改。

插件在这里: https://pub.dartlang.org/flutter/packages?q=flutter_search_bar&api=0

更新:这是我的代码现在的样子

  _NavigationState() {
searchBar = new SearchBar(
controller: controller,
inBar: false,
setState: setState,
onSubmitted: onSubmit,
onChanged: onChange,
buildDefaultAppBar: buildAppBar,
hintText: 'Search Book',
closeOnSubmit: false,
clearOnSubmit: true,
onClosed: onClosed,
);
}

void onClosed() {
isSeaching = false;
loadTabpages();
setState(() {});
}

最佳答案

您可以 fork repo 并进行更改:

https://github.com/ArcticZeroo/flutter-search-bar/blob/master/lib/src/flutter_search_bar_base.dart

在 SearchBar 类中添加这个变量:

     /// Event triggered when the user close the search bar
final VoidCallback onClosed;

将字段添加到构造函数中

      SearchBar(
{@required this.setState,
@required this.buildDefaultAppBar,
this.onSubmitted,
this.controller,
this.hintText = 'Search',
this.inBar = true,
this.colorBackButton = true,
this.closeOnSubmit = true,
this.clearOnSubmit = true,
this.showClearButton = true,
this.onChanged,
this.onClosed})

第 144 行

将小部件设置为前导属性

         new IconButton(
icon: const BackButtonIcon(),
color: buttonColor,
tooltip: MaterialLocalizations.of(context).backButtonTooltip,
onPressed: () {
if (onClosed != null) {
onClosed();
}
Navigator.maybePop(context);
}),

使用监听器:

    new SearchBar(
inBar: true,
setState: setState,
showClearButton: false,
clearOnSubmit: false,
closeOnSubmit: false,
onClosed: () {

}), ...

更新后退按钮的处理方式

    return new AppBar(
leading: WillPopScope(
onWillPop: () {
if (onClosed != null) {
onClosed();
}
return Future.value(true);
},
child: new IconButton(
icon: const BackButtonIcon(),
color: buttonColor,
tooltip: MaterialLocalizations.of(context).backButtonTooltip,
onPressed: () {
if (onClosed != null) {
onClosed();
}
controller.clear();
Navigator.maybePop(context);
}),
),

....

关于dart - flutter_search_bar 插件 onClose 监听器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51940871/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com