I'm trying to make a UI in flutter wherein I'm using SliverAppBar(I mention this because I need to use either CustomScrollView or NestedScrollView) and now in the body, I was to make the first two elements not scroll when they reach the top of the screen while the bottom list does. Using CustomScrollView, it either scrolls as a whole or does not at all(Appbar included). In NestedScrollView, if i use NeverScrollableScrollPhysics, the appbar scrolls and the body does not. Now I can either make the whole body scrollable or i get a pixel error. Please help me.
I have added the NestedScrollView code below. I need the search bar and the go to cart container to get fixed at the top once the sliver bar disappears.
NestedScrollView(
physics: NeverScrollableScrollPhysics(),
headerSliverBuilder: (BuildContext context, bool innerBoxIsScrolled) {
return <Widget>[
SliverAppBar(
backgroundColor: Color(0xffececec),
shadowColor: Colors.transparent,
iconTheme: IconThemeData(color: Colors.black),
pinned: false,
centerTitle: true,
expandedHeight: 200.0,
floating: false,
forceElevated: innerBoxIsScrolled,
// snap: true,
flexibleSpace: SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: Container(
padding: EdgeInsets.only(top: 80),
child: Row(
children: [
banner(
image),
banner(
image),
banner(
image),
],
),
)),
actions: [
InkWell(
onTap: () {
Navigator.push(
context, MaterialPageRoute(builder: (_) => Cart()));
},
child: Icon(
Icons.shopping_cart,
color: Colors.black,
),
),
SizedBox(width: Units.width(context) * 0.03),
],
)
];
},
body: SingleChildScrollView(
physics: NeverScrollableScrollPhysics(),
child: Column(
children: [
Row(
children: [
Text('Search'),
Icon(
FontAwesomeIcons.search,
color: Colors.white,
),
],
),
Container(
height: Units.height(context) * 0.1,
width: Units.height(context) * 0.17,
child: Text(
"Go to cart",
style: TextStyle(
fontSize: Units.regularText(context) * 0.9,
fontWeight: FontWeight.bold),
),
),
ListView(
shrinkWrap: true,
physics: AlwaysScrollableScrollPhysics(),
children: [
Center(
child: Wrap(
children: [
lappyCard(context),
lappyCard(context),
lappyCard(context),
lappyCard(context),
lappyCard(context),
lappyCard(context),
lappyCard(context),
lappyCard(context),
lappyCard(context),
],
),
),
],
),
],
),
),
),