美文网首页Flutter
Flutter 自定义SearchDelegate搜索页面

Flutter 自定义SearchDelegate搜索页面

作者: Karedem | 来源:发表于2019-08-15 17:11 被阅读0次

日常开发中 我们可能会用到 SearchDelegate 来实现一个搜索页面

但是对外只暴露了以下几个接口

buildActions()

buildLeading()

buildResults()

buildSuggestion() 等等

如果我们想自定义 TextField , 修改hintText内容

或者AppBar下还想添加一个bottom怎么办呢, 这边提供一个方法以供参考

定义一个ASearchDelegate 继承自 SearchDelegate, 把SearchDelegate 源码都拷进来(material\search.dart) 

showSearch方法也换个名 showASearch(内部类可以都加个A前缀以区分, 同时继承一下原有类)

接着 找到_ASearchPageState 的build方法 

会返回一个Semantics 对象, 其实整个搜索页面就在这里定义的啦

ok, 就在这里自由发挥了

下图是题主的改动

对应调用处则调整为: showASearch(context, ASearchDelegate());

效果图:

相关文章

网友评论

    本文标题:Flutter 自定义SearchDelegate搜索页面

    本文链接:https://www.haomeiwen.com/subject/nnpupttx.html