showSearchPage<T> function
Implementation
Future<T?> showSearchPage<T>(BuildContext context, SearchPage searchPage) {
final child = Scaffold(
body: SafeArea(
bottom: false,
child: Column(
children: [
Hero(
tag: searchBarHeroTag,
child: Material(
child: _SearchBar(
controller: searchPage.textEditingController,
focusNode: searchPage.focusNode,
hintText: searchPage.hintText,
onChanged: searchPage.textChange,
onSeached: searchPage.search,
// 设置true,和动画时间有冲突
autofocus: false,
),
),
),
Expanded(child: searchPage.build(context)),
],
),
),
);
// 直接用设置 autofocus 和动画时间有冲突, 之所以设置350毫秒是因为动画时间是300毫秒。
// 系统的处理方式是将动画传给widget,设置动画Listener,动画结束再requestFocus
if (searchPage.autofocus) {
Future.delayed(
const Duration(milliseconds: 350),
() => searchPage.focusNode.requestFocus(),
);
}
return Navigator.push(context, _SearchPageRoute<T>(child));
}