How to make the Collapsable AppBar scroll as well while using the GridView Scroll in Flutter ?












0















I need my Collapsable AppBar to scroll when I am scrolling in my GridView ? I would like to achieve this without deactivating my GridView scroll-controller as I require it for infinite scroll implementation later on.



The below code has a Collapsable AppBar and A GridView of Cards inside it. Since my GridView has a height nearly as that of the entire page, once I start scrolling - my collapsable AppBar stops scrolling and only my GridView Elements scroll within the GridView. This looks ugly as the AppBar stops half way through before it completely collapses.



import  'package:flutter/material.dart';

_MockPageState mockPageState = new _MockPageState();

class MockPage extends StatefulWidget {
MockPage({
Key key,
}) : super(key: key);

@override
_MockPageState createState() => new _MockPageState();
}

class _MockPageState extends State<MockPage> {

@override
void initState() {
super.initState();
}

Widget displayCards(index){
return new Card(
elevation: 6.0,
child: new Container(
color: Colors.blue,
child: new Center(
child: new Container(
padding: const EdgeInsets.all(2.0),
child: new Text(
"This cards is a widget of the GridView",
style: TextStyle(
color: Colors.black,
fontSize: 13.0,
fontStyle: FontStyle.normal,
),
textAlign: TextAlign.justify,
maxLines: 3,
overflow: TextOverflow.ellipsis,
),
),
),
)
);
}

Widget displayDetails()
{
double screenheight = MediaQuery.of(context).size.height;
var orientation = MediaQuery.of(context).orientation;
return new Container(
color: Colors.greenAccent,
padding: const EdgeInsets.all(5.0),
height: screenheight - 30.0,
child: new GridView.builder(
physics: new NeverScrollableScrollPhysics(),
shrinkWrap: true,
primary: true,
gridDelegate: new SliverGridDelegateWithFixedCrossAxisCount(
childAspectRatio: 1.0,
mainAxisSpacing: 10.0,
crossAxisSpacing: 10.0,
crossAxisCount: (orientation == Orientation.portrait) ? 3 : 3,
),
padding: const EdgeInsets.all(20.0),
itemCount: 20,
scrollDirection: Axis.vertical,
itemBuilder: (BuildContext context, int index) {
return new GridTile(
child: displayCards(index),
);
},
),
);
}


Widget heroBackground(){
double screenWidth = MediaQuery.of(context).size.width;
double screenheight = MediaQuery.of(context).size.height;
return new Container(
color: Colors.yellow,
child: new Container(
width: screenWidth,
height: screenheight * 0.6,
decoration: new BoxDecoration(color: Colors.yellow,),
child: new Stack(
children: <Widget>[
new Positioned.fill(
child: new Container(
color: Colors.yellow,
),
),
],
),
),
);
}

Widget collapsingAppBar(){
var screenheight = MediaQuery.of(context).size.height;
return new SliverAppBar(
leading: IconButton(icon:Icon(Icons.arrow_back, color: Colors.black,),onPressed:() => Navigator.pop(context)),
title: new Text(
"Collapsable App Bar (Yellow)",
style: TextStyle(
color: Colors.black,
fontSize: 16.0,
fontStyle: FontStyle.normal
),
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
expandedHeight: screenheight * 0.60,
floating: false,
pinned: true,
backgroundColor: Colors.white,
flexibleSpace: FlexibleSpaceBar(
centerTitle: true,
background: heroBackground(),
),
);
}

@override
Widget build(BuildContext context) {
return new Scaffold(
resizeToAvoidBottomPadding: false,
body: new NestedScrollView(
headerSliverBuilder: (BuildContext context, bool innerBoxIsScrolled) {
return <Widget>[
collapsingAppBar(),
];
},
body: new Container(
color: Colors.white,
child : new SingleChildScrollView(
child: new ConstrainedBox(
constraints: new BoxConstraints(),
child : displayDetails(),
),
),
),
),
);
}
}









share|improve this question



























    0















    I need my Collapsable AppBar to scroll when I am scrolling in my GridView ? I would like to achieve this without deactivating my GridView scroll-controller as I require it for infinite scroll implementation later on.



    The below code has a Collapsable AppBar and A GridView of Cards inside it. Since my GridView has a height nearly as that of the entire page, once I start scrolling - my collapsable AppBar stops scrolling and only my GridView Elements scroll within the GridView. This looks ugly as the AppBar stops half way through before it completely collapses.



    import  'package:flutter/material.dart';

    _MockPageState mockPageState = new _MockPageState();

    class MockPage extends StatefulWidget {
    MockPage({
    Key key,
    }) : super(key: key);

    @override
    _MockPageState createState() => new _MockPageState();
    }

    class _MockPageState extends State<MockPage> {

    @override
    void initState() {
    super.initState();
    }

    Widget displayCards(index){
    return new Card(
    elevation: 6.0,
    child: new Container(
    color: Colors.blue,
    child: new Center(
    child: new Container(
    padding: const EdgeInsets.all(2.0),
    child: new Text(
    "This cards is a widget of the GridView",
    style: TextStyle(
    color: Colors.black,
    fontSize: 13.0,
    fontStyle: FontStyle.normal,
    ),
    textAlign: TextAlign.justify,
    maxLines: 3,
    overflow: TextOverflow.ellipsis,
    ),
    ),
    ),
    )
    );
    }

    Widget displayDetails()
    {
    double screenheight = MediaQuery.of(context).size.height;
    var orientation = MediaQuery.of(context).orientation;
    return new Container(
    color: Colors.greenAccent,
    padding: const EdgeInsets.all(5.0),
    height: screenheight - 30.0,
    child: new GridView.builder(
    physics: new NeverScrollableScrollPhysics(),
    shrinkWrap: true,
    primary: true,
    gridDelegate: new SliverGridDelegateWithFixedCrossAxisCount(
    childAspectRatio: 1.0,
    mainAxisSpacing: 10.0,
    crossAxisSpacing: 10.0,
    crossAxisCount: (orientation == Orientation.portrait) ? 3 : 3,
    ),
    padding: const EdgeInsets.all(20.0),
    itemCount: 20,
    scrollDirection: Axis.vertical,
    itemBuilder: (BuildContext context, int index) {
    return new GridTile(
    child: displayCards(index),
    );
    },
    ),
    );
    }


    Widget heroBackground(){
    double screenWidth = MediaQuery.of(context).size.width;
    double screenheight = MediaQuery.of(context).size.height;
    return new Container(
    color: Colors.yellow,
    child: new Container(
    width: screenWidth,
    height: screenheight * 0.6,
    decoration: new BoxDecoration(color: Colors.yellow,),
    child: new Stack(
    children: <Widget>[
    new Positioned.fill(
    child: new Container(
    color: Colors.yellow,
    ),
    ),
    ],
    ),
    ),
    );
    }

    Widget collapsingAppBar(){
    var screenheight = MediaQuery.of(context).size.height;
    return new SliverAppBar(
    leading: IconButton(icon:Icon(Icons.arrow_back, color: Colors.black,),onPressed:() => Navigator.pop(context)),
    title: new Text(
    "Collapsable App Bar (Yellow)",
    style: TextStyle(
    color: Colors.black,
    fontSize: 16.0,
    fontStyle: FontStyle.normal
    ),
    maxLines: 1,
    overflow: TextOverflow.ellipsis,
    ),
    expandedHeight: screenheight * 0.60,
    floating: false,
    pinned: true,
    backgroundColor: Colors.white,
    flexibleSpace: FlexibleSpaceBar(
    centerTitle: true,
    background: heroBackground(),
    ),
    );
    }

    @override
    Widget build(BuildContext context) {
    return new Scaffold(
    resizeToAvoidBottomPadding: false,
    body: new NestedScrollView(
    headerSliverBuilder: (BuildContext context, bool innerBoxIsScrolled) {
    return <Widget>[
    collapsingAppBar(),
    ];
    },
    body: new Container(
    color: Colors.white,
    child : new SingleChildScrollView(
    child: new ConstrainedBox(
    constraints: new BoxConstraints(),
    child : displayDetails(),
    ),
    ),
    ),
    ),
    );
    }
    }









    share|improve this question

























      0












      0








      0








      I need my Collapsable AppBar to scroll when I am scrolling in my GridView ? I would like to achieve this without deactivating my GridView scroll-controller as I require it for infinite scroll implementation later on.



      The below code has a Collapsable AppBar and A GridView of Cards inside it. Since my GridView has a height nearly as that of the entire page, once I start scrolling - my collapsable AppBar stops scrolling and only my GridView Elements scroll within the GridView. This looks ugly as the AppBar stops half way through before it completely collapses.



      import  'package:flutter/material.dart';

      _MockPageState mockPageState = new _MockPageState();

      class MockPage extends StatefulWidget {
      MockPage({
      Key key,
      }) : super(key: key);

      @override
      _MockPageState createState() => new _MockPageState();
      }

      class _MockPageState extends State<MockPage> {

      @override
      void initState() {
      super.initState();
      }

      Widget displayCards(index){
      return new Card(
      elevation: 6.0,
      child: new Container(
      color: Colors.blue,
      child: new Center(
      child: new Container(
      padding: const EdgeInsets.all(2.0),
      child: new Text(
      "This cards is a widget of the GridView",
      style: TextStyle(
      color: Colors.black,
      fontSize: 13.0,
      fontStyle: FontStyle.normal,
      ),
      textAlign: TextAlign.justify,
      maxLines: 3,
      overflow: TextOverflow.ellipsis,
      ),
      ),
      ),
      )
      );
      }

      Widget displayDetails()
      {
      double screenheight = MediaQuery.of(context).size.height;
      var orientation = MediaQuery.of(context).orientation;
      return new Container(
      color: Colors.greenAccent,
      padding: const EdgeInsets.all(5.0),
      height: screenheight - 30.0,
      child: new GridView.builder(
      physics: new NeverScrollableScrollPhysics(),
      shrinkWrap: true,
      primary: true,
      gridDelegate: new SliverGridDelegateWithFixedCrossAxisCount(
      childAspectRatio: 1.0,
      mainAxisSpacing: 10.0,
      crossAxisSpacing: 10.0,
      crossAxisCount: (orientation == Orientation.portrait) ? 3 : 3,
      ),
      padding: const EdgeInsets.all(20.0),
      itemCount: 20,
      scrollDirection: Axis.vertical,
      itemBuilder: (BuildContext context, int index) {
      return new GridTile(
      child: displayCards(index),
      );
      },
      ),
      );
      }


      Widget heroBackground(){
      double screenWidth = MediaQuery.of(context).size.width;
      double screenheight = MediaQuery.of(context).size.height;
      return new Container(
      color: Colors.yellow,
      child: new Container(
      width: screenWidth,
      height: screenheight * 0.6,
      decoration: new BoxDecoration(color: Colors.yellow,),
      child: new Stack(
      children: <Widget>[
      new Positioned.fill(
      child: new Container(
      color: Colors.yellow,
      ),
      ),
      ],
      ),
      ),
      );
      }

      Widget collapsingAppBar(){
      var screenheight = MediaQuery.of(context).size.height;
      return new SliverAppBar(
      leading: IconButton(icon:Icon(Icons.arrow_back, color: Colors.black,),onPressed:() => Navigator.pop(context)),
      title: new Text(
      "Collapsable App Bar (Yellow)",
      style: TextStyle(
      color: Colors.black,
      fontSize: 16.0,
      fontStyle: FontStyle.normal
      ),
      maxLines: 1,
      overflow: TextOverflow.ellipsis,
      ),
      expandedHeight: screenheight * 0.60,
      floating: false,
      pinned: true,
      backgroundColor: Colors.white,
      flexibleSpace: FlexibleSpaceBar(
      centerTitle: true,
      background: heroBackground(),
      ),
      );
      }

      @override
      Widget build(BuildContext context) {
      return new Scaffold(
      resizeToAvoidBottomPadding: false,
      body: new NestedScrollView(
      headerSliverBuilder: (BuildContext context, bool innerBoxIsScrolled) {
      return <Widget>[
      collapsingAppBar(),
      ];
      },
      body: new Container(
      color: Colors.white,
      child : new SingleChildScrollView(
      child: new ConstrainedBox(
      constraints: new BoxConstraints(),
      child : displayDetails(),
      ),
      ),
      ),
      ),
      );
      }
      }









      share|improve this question














      I need my Collapsable AppBar to scroll when I am scrolling in my GridView ? I would like to achieve this without deactivating my GridView scroll-controller as I require it for infinite scroll implementation later on.



      The below code has a Collapsable AppBar and A GridView of Cards inside it. Since my GridView has a height nearly as that of the entire page, once I start scrolling - my collapsable AppBar stops scrolling and only my GridView Elements scroll within the GridView. This looks ugly as the AppBar stops half way through before it completely collapses.



      import  'package:flutter/material.dart';

      _MockPageState mockPageState = new _MockPageState();

      class MockPage extends StatefulWidget {
      MockPage({
      Key key,
      }) : super(key: key);

      @override
      _MockPageState createState() => new _MockPageState();
      }

      class _MockPageState extends State<MockPage> {

      @override
      void initState() {
      super.initState();
      }

      Widget displayCards(index){
      return new Card(
      elevation: 6.0,
      child: new Container(
      color: Colors.blue,
      child: new Center(
      child: new Container(
      padding: const EdgeInsets.all(2.0),
      child: new Text(
      "This cards is a widget of the GridView",
      style: TextStyle(
      color: Colors.black,
      fontSize: 13.0,
      fontStyle: FontStyle.normal,
      ),
      textAlign: TextAlign.justify,
      maxLines: 3,
      overflow: TextOverflow.ellipsis,
      ),
      ),
      ),
      )
      );
      }

      Widget displayDetails()
      {
      double screenheight = MediaQuery.of(context).size.height;
      var orientation = MediaQuery.of(context).orientation;
      return new Container(
      color: Colors.greenAccent,
      padding: const EdgeInsets.all(5.0),
      height: screenheight - 30.0,
      child: new GridView.builder(
      physics: new NeverScrollableScrollPhysics(),
      shrinkWrap: true,
      primary: true,
      gridDelegate: new SliverGridDelegateWithFixedCrossAxisCount(
      childAspectRatio: 1.0,
      mainAxisSpacing: 10.0,
      crossAxisSpacing: 10.0,
      crossAxisCount: (orientation == Orientation.portrait) ? 3 : 3,
      ),
      padding: const EdgeInsets.all(20.0),
      itemCount: 20,
      scrollDirection: Axis.vertical,
      itemBuilder: (BuildContext context, int index) {
      return new GridTile(
      child: displayCards(index),
      );
      },
      ),
      );
      }


      Widget heroBackground(){
      double screenWidth = MediaQuery.of(context).size.width;
      double screenheight = MediaQuery.of(context).size.height;
      return new Container(
      color: Colors.yellow,
      child: new Container(
      width: screenWidth,
      height: screenheight * 0.6,
      decoration: new BoxDecoration(color: Colors.yellow,),
      child: new Stack(
      children: <Widget>[
      new Positioned.fill(
      child: new Container(
      color: Colors.yellow,
      ),
      ),
      ],
      ),
      ),
      );
      }

      Widget collapsingAppBar(){
      var screenheight = MediaQuery.of(context).size.height;
      return new SliverAppBar(
      leading: IconButton(icon:Icon(Icons.arrow_back, color: Colors.black,),onPressed:() => Navigator.pop(context)),
      title: new Text(
      "Collapsable App Bar (Yellow)",
      style: TextStyle(
      color: Colors.black,
      fontSize: 16.0,
      fontStyle: FontStyle.normal
      ),
      maxLines: 1,
      overflow: TextOverflow.ellipsis,
      ),
      expandedHeight: screenheight * 0.60,
      floating: false,
      pinned: true,
      backgroundColor: Colors.white,
      flexibleSpace: FlexibleSpaceBar(
      centerTitle: true,
      background: heroBackground(),
      ),
      );
      }

      @override
      Widget build(BuildContext context) {
      return new Scaffold(
      resizeToAvoidBottomPadding: false,
      body: new NestedScrollView(
      headerSliverBuilder: (BuildContext context, bool innerBoxIsScrolled) {
      return <Widget>[
      collapsingAppBar(),
      ];
      },
      body: new Container(
      color: Colors.white,
      child : new SingleChildScrollView(
      child: new ConstrainedBox(
      constraints: new BoxConstraints(),
      child : displayDetails(),
      ),
      ),
      ),
      ),
      );
      }
      }






      scroll dart flutter






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 23 '18 at 9:08









      Keshav Aditya R.PKeshav Aditya R.P

      7121515




      7121515
























          0






          active

          oldest

          votes











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53443568%2fhow-to-make-the-collapsable-appbar-scroll-as-well-while-using-the-gridview-scrol%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes
















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53443568%2fhow-to-make-the-collapsable-appbar-scroll-as-well-while-using-the-gridview-scrol%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          404 Error Contact Form 7 ajax form submitting

          How to know if a Active Directory user can login interactively

          TypeError: fit_transform() missing 1 required positional argument: 'X'