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

后端 未结 9 1442
滥情空心
滥情空心 2020-12-28 12:42

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 separat

9条回答
  •  天涯浪人
    2020-12-28 12:59

    You can use Scaffold's property "extendBodyBehindAppBar: true" Don't forget to wrap child with SafeArea

      @Override
      Widget build(BuildContext context) {
        return Scaffold(
          appBar: AppBar(
            title: Text(
              widget.title,
              style: TextStyle(color: Colors.black),
            ),
            backgroundColor: Colors.transparent,
            elevation: 0.0,
          ),
          extendBodyBehindAppBar: true,
          body: Container(
            width: double.infinity,
            height: double.infinity,
            decoration: BoxDecoration(
              image: DecorationImage(
                image: AssetImage('assets/background/home.png'),
                fit: BoxFit.cover,
              ),
            ),
            child: SafeArea(
                child: Center(
              child: Container(
                width: 300,
                height: 300,
                decoration: BoxDecoration(
                  color: Colors.green,
                ),
                child: Center(child: Text('Test')),
              ),
            )),
          ),
        );
      }
    

提交回复
热议问题