Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Appbar getting trasnparent and shows content under it

I am trying to achieve appbar animation. I have achieved the animation required but app bar is getting transparent. I dont know why this is happening. Can someone help resolving the issue?

Here is the code

  bool showAppbar = false;
  bool isScrollingDown = true;
  ScrollController controller = ScrollController();

  @override
  void initState() {
    super.initState();
    controller.addListener(() {
      if (controller.position.userScrollDirection == ScrollDirection.forward) {
        if (!isScrollingDown) {
          isScrollingDown = true;
          showAppbar = false;
          setState(() {});
        }
      }

  if (controller.position.userScrollDirection == ScrollDirection.reverse) {
    if (isScrollingDown && controller.position.pixels > 200) {
      isScrollingDown = false;
      showAppbar = true;
      setState(() {});
    }
  }
});


}



@override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: Column(
          children: [
            Expanded(
              child: Stack(
                children: [
                  AnimatedContainer(
                    duration: const Duration(
                      milliseconds: 150,
                    ),
                    height: showAppbar ? 90 : 0,
                    child: AppBar(
                      title: Text(widget.title),
                      backgroundColor: Colors.redAccent,
                    ),
                  ),
                  Expanded(
                    child: ListView.builder(
                      itemBuilder: (context, index) {
                        return Text("data $index");
                      },
                      itemCount: 60,
                      controller: controller,
                    ),
                  ),
                ],
              ),
            ),
          ],
        ),
      ), // This trailing comma makes auto-formatting nicer for build methods.
    );
  }

This is the resultenter image description here

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

I dont want the Listview rows showing behind the appbar.

>Solution :

You need to change the order inside your stack widget:

Stack(
        children: [
          Expanded(
            child: ListView.builder(
              itemBuilder: (context, index) {
                return Text("data $index");
              },
              itemCount: 60,
              controller: controller,
            ),
          ),
          AnimatedContainer(
            duration: const Duration(
              milliseconds: 150,
            ),
            height: showAppbar ? 90 : 0,
            child: AppBar(
              title: Text(widget.title),
              backgroundColor: Colors.redAccent,
            ),
          ),
        ],
      )
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading