gpt4 book ai didi

flutter - 如何让我的 appbar 在灵活的 app bar 的同时充当 Material 搜索小部件

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

我希望我的应用栏在向下滚动或用户搜索内容时充当固定的应用栏。

SliverAppBar(
title: new TextField(
style: Theme.of(context).primaryTextTheme.title,
decoration: InputDecoration(
hintText: '검색',
),
),
),

searching


但我想在向上滚动且用户未搜索时将其绘制为灵活的应用栏。

flexibleSpace: new FlexibleSpaceBar(
centerTitle: false,
title: new TextField(
style: Theme.of(context).primaryTextTheme.title,
decoration: InputDecoration(
hintText: '검색',
),
),
background: Stack(
fit: StackFit.expand,
children: <Widget>[
SizedBox(
height: 256.0,
child: Container(
child: Padding(
padding: const EdgeInsets.only(top: 24.0),
child: Column(
children: <Widget>[
Align(
alignment: Alignment.topLeft,
child: FlutterLogo(
size: 64.0,
),
),
Padding(padding: const EdgeInsets.only(bottom: 24.0)),
ListTile(
title: Text('Some Text'),
),
],
),
),
),
),
// This gradient ensures that the toolbar icons are distinct
// against the background image.
],
),
),

scrolled-up

当使用第二种方法向上滚动时,搜索字段会转换到右上角。

最佳答案

将title内容移动到另一个SliverList中可以达到效果。

从 SliverAppBar 中移除 flexibleSpace,并将 flexibleSpace.background 的内容移动到 SliverList 之前 SliverAppBar。

例子:

@override
Widget build(BuildContext context) {
return new CustomScrollView(
slivers: <Widget>[
new SliverList(
delegate: new SliverChildListDelegate(<Widget>[
Align(
alignment: Alignment.topLeft,
child: FlutterLogo(size: 64.0),
),
ListTile(
title: Text('Some Text'),
),
ListTile(),
])),
new SliverAppBar(
backgroundColor: Theme.of(context).scaffoldBackgroundColor,
elevation: 0.0,
automaticallyImplyLeading: false,
pinned: true,
floating: false,
title: new TextField(
focusNode: _searchFocusNode,
style: Theme.of(context).primaryTextTheme.title,
decoration: InputDecoration(
border: OutlineInputBorder(borderRadius: BorderRadius.all(Radius.circular(8.0))),
suffixIcon: Icon(Icons.search),
hintText: '검색',
),
),
),
new SliverList(
delegate: new SliverChildListDelegate(List.generate(
100,
(i) => ListTile(
title: Text('Scroll'),
)).toList()),
),
],
);
}

关于flutter - 如何让我的 appbar 在灵活的 app bar 的同时充当 Material 搜索小部件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52563949/

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