Flutter: Transparent clipped AppBar

105

try this:

Scaffold(
  extendBodyBehindAppBar: true,

this will make items behind appbar visible

Share:
105
Josip Domazet
Author by

Josip Domazet

Updated on January 03, 2023

Comments

  • Josip Domazet
    Josip Domazet over 1 year

    I have a waved app bar that looks like this:

    appbar

    As you can see the clipped area is not transparent but rather has the (black) canvas color and is blocking some ListView entries.

    The code for the app bar looks something like this:

    class MainAppBar extends StatelessWidget implements PreferredSizeWidget {
    ...
    @override
    Widget build(BuildContext context) {
        return PreferredSize(
            child: ClipPath(
              clipper: WaveClip(),
              child: Container(
                color: getAppBarColor(),
                child: Column(
                  mainAxisAlignment: MainAxisAlignment.center,
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: <Widget>[
                    ...
                  ],
                ),
              ),
            ),
            preferredSize: const Size.fromHeight(kToolbarHeight + 60));
      }
    }
    

    As one can see I am using a ClipPath with a custom clipper to clip a Container. How do I clip it in a transparent manner?

  • Josip Domazet
    Josip Domazet over 2 years
    This did not have an effect. Afaik this is useful for appbars that are somewhat transparent. But my appbar is not transparent yet and that's the problem. The cut parts need to be transparent.
  • Jim
    Jim over 2 years
    what if you change nesting of PreferredSize to inner, updated
  • Josip Domazet
    Josip Domazet over 2 years
    Ok the problem was that one child widget of the body was a SafeArea hence negating all effects of extendBodyBehindAppBar. Your original answer was correct. Thank you.
  • Jim
    Jim over 2 years
    good to hear that, i will update back to original one, happy coding!