I want to achieve something like this using a SliverAppBar
with a TextField
inside for my search. When users scroll up, the TextField
should scroll up pinning itself to the appBar
. However, I have been unable to achieve this.
This is my code:
return CustomScrollView(
slivers: <Widget>[
SliverAppBar(
stretch: false,
expandedHeight: 200.0,
floating: false, //This is not needed since it's default
pinned: true,
flexibleSpace: FlexibleSpaceBar(
centerTitle: true,
title: Container(
height: 50,
child: TextField(
decoration: InputDecoration(
hintText: "Search",
fillColor: Colors.white,
filled: true,
suffixIcon: Icon(Icons.filter_list),
enabledBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(20.0),
borderSide: BorderSide(color: Colors.transparent),
),
contentPadding:
EdgeInsets.symmetric(horizontal: 16.0, vertical: 16.0)
),
),
)
),
),
SliverFillRemaining(
child: new Center(
child: new Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
new Text(
'You have pushed the button this many times:',
),
new Text(
'',
style: Theme
.of(context)
.textTheme
.display1,
),
],
),
),
),
],
);
My search is stretched beyond bounds when appBar
is expanded and doesn't work well while scrolling up. What do I do?