首页 > 解决方案 > 在以下情况下使 appbar 透明

问题描述

伙计们!我正在尝试使这个 AppBar 透明。因为它背后会有背景,但到目前为止我还没有成功。我谢谢大家谢谢!

class _HomePageState extends State<HomePage> {
  int index = 0;
  Widget build(BuildContext context) {
    return Scaffold(
      body: show(index),
      appBar: AppBar(
        backgroundColor: Colors.transparent,
        actions: <Widget>[
          IconButton(
            icon: Icon(Icons.settings),
            onPressed: (){},
          )
        ],
      ),
      bottomNavigationBar: Theme(
        data: Theme.of(context).copyWith(
          canvasColor: Colors.grey[900],
        ),
        child: BottomNavigationBar(
          type: BottomNavigationBarType.fixed,
          currentIndex: index,
          showUnselectedLabels: true,
          unselectedItemColor: Colors.white54,
          selectedItemColor: Colors.white,
          onTap: ((int x) {
            setState(() {
              index = x;
            });
          }),
          items: [
            new BottomNavigationBarItem(
                icon: Icon(Icons.home), title: Text("Home")),
            new BottomNavigationBarItem(
                icon: Icon(Icons.search), title: Text("Search")),
            new BottomNavigationBarItem(
                icon: Icon(Icons.library_music), title: Text("Library")),
          ],
        ),
      ),
    );
  }
}

在此处输入图像描述

标签: flutterdartflutter-layouttransparentappbar

解决方案


Appbar默认有阴影,如果你想要透明的appbar,你还需要添加elevation: 0AppBar删除阴影。


推荐阅读