您可以使用带有透明应用程序栏和底部应用程序栏的可滑动选项卡吗?

时间:2019-04-21 09:30:18

标签: flutter transparency flutter-appbar

我正在尝试构建一个具有透明应用程序栏和底部应用程序栏的颤振布局。但是,我希望能够在选项卡之间滑动。问题是我可以有可滑动的选项卡,但主体不位于应用栏的下方。或者,我可以将主体放在应用程序栏的下面,但是选项卡不可滑动。

我已经尝试过使用Stack()而不是Scaffold()的实现。但是,由于无法区分主体栏和应用栏,我认为这会将TabBarView放在应用栏的前面。

这是不显示应用栏的代码:

class _AppStateTab extends State<App>{
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: DefaultTabController(
        length: 3,
        child: Stack(
          children: <Widget>[
            Positioned(
              top: 0.0,
              left: 0.0,
              right: 0.0,
              child: AppBar(
                backgroundColor: Colors.transparent,
                elevation: 0.0,
                actions: <Widget>[
                  IconButton(
                    icon: Icon(Icons.search), 
                    color: Colors.white,
                    onPressed: () {},
                  ),
                  IconButton(
                    icon: Icon(Icons.cached), 
                    color: Colors.white,
                    onPressed: () {},
                  ),
                ],
              ),
            ),
            Positioned(
              bottom: 0.0,
              left: 0.0,
              right: 0.0,
              child: BottomAppBar(
                color: Colors.transparent,
                elevation: 0.0,
                child: Row(
                  mainAxisSize: MainAxisSize.max,
                  mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                  children: <Widget>[
                    IconButton(
                      icon: Icon(Icons.dialpad), 
                      color: Colors.white,
                      onPressed: (){},
                    ),
                    IconButton(
                      icon: Icon(Icons.camera_alt),
                      color: Colors.white,
                      onPressed: (){},
                    ),
                    IconButton(
                      icon: Icon(Icons.edit),
                      color: Colors.white,
                      onPressed: (){},
                    ),
                  ],
                ),
              ),
            ),
            TabBarView(
              children: <Widget>[
                Calculator(),
                Camera(),
                Solution(),
              ],
            )
          ],
        ),
      ),
    );
  }
}

这是代码在其中实体不会在应用栏下方移动的代码:

  @override
  Widget build(BuildContext context){
    return Scaffold(
      appBar: AppBar(
        title: Text('data'),
        backgroundColor: Colors.transparent,
        elevation: 0.0,
      ),
      body: TabBarView(
        controller: _tabController,
        children: _tabList,
      ),
      bottomNavigationBar: BottomAppBar(
        color: Colors.transparent,
        elevation: 0.0,
        child: Row(
          mainAxisSize: MainAxisSize.max,
          mainAxisAlignment: MainAxisAlignment.spaceEvenly,
          children: <Widget>[
            IconButton(
              icon: Icon(Icons.dialpad), 
              color: Colors.white,
              onPressed: (){
                _tabController.animateTo(0);
              },
            ),
            IconButton(
              icon: Icon(Icons.camera_alt),
              color: Colors.white,
              onPressed: (){
                _tabController.animateTo(1);
              },
            ),
            IconButton(
              icon: Icon(Icons.edit),
              color: Colors.white,
              onPressed: (){
                _tabController.animateTo(2);
              },
            ),
          ],
        ),
      ),
    );

1 个答案:

答案 0 :(得分:0)

好吧,只是更新,我设法解决了我的问题。可以这么说,我没有意识到堆栈中的顺序决定了它的层。第一项位于最后面,彼此之间位于另一层。因此,为了解决这个问题,我将车身重新布置为第一位,并按照位置进行了定位。这允许带有透明应用栏的可滑动应用。