Make AppBar transparent and show background image which is set to whole screen

Rahul Mahadik picture Rahul Mahadik · Oct 31, 2018 · Viewed 89.5k times · Source

I have added AppBar in my flutter application. My screen already have a background image, where i don't want to set appBar color or don't want set separate background image to appBar.

I want show same screen background image to appBar also.

I already tried by setting appBar color as transparent but it shows color like gray.

Example code:

appBar: new AppBar(
        centerTitle: true,
//        backgroundColor: Color(0xFF0077ED),
        elevation: 0.0,
        title: new Text(
            "DASHBOARD",
            style: const TextStyle(
                color:  const Color(0xffffffff),
                fontWeight: FontWeight.w500,
                fontFamily: "Roboto",
                fontStyle:  FontStyle.normal,
                fontSize: 19.0
            )),
      )

enter image description here

Answer

gswierczynski picture gswierczynski · Dec 30, 2019

This is supported by Scaffold now (in stable - v1.12.13+hotfix.5).

  • Set Scaffold extendBodyBehindAppBar to true,
  • Set AppBar elevation to 0 to get rid of shadow,
  • Set AppBar backgroundColor transparency as needed.
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      extendBodyBehindAppBar: true,
      backgroundColor: Colors.red,
      appBar: AppBar(
//        backgroundColor: Colors.transparent,
        backgroundColor: Color(0x44000000),
        elevation: 0,
        title: Text("Title"),
      ),
      body: Center(child: Text("Content")),
    );
  }