如何将缺口添加到TabBar以将FloatingActionButton放置在其中

时间:2018-08-16 15:54:14

标签: dart flutter navigationbar tabview floating-action-button

我想在TabBar内创建一个凹口,将FloatingActionBottom放置在其中,但我不知道该怎么做。

我在文档或互联网上什么都没找到。

FloatingActionButton on BottomNavigationBar

3 个答案:

答案 0 :(得分:3)

您可以将Bottom App Bar用于此类用户界面 BottomAppBar的hasNotch属性必须为true。

这会让你明白我的意思

Widget build(BuildContext context) {
  return new Scaffold(
    appBar: AppBar(title: const Text('Bottom App Bar')),
    floatingActionButtonLocation: 
      FloatingActionButtonLocation.centerDocked,
    floatingActionButton: FloatingActionButton(
      child: const Icon(Icons.add), onPressed: () {},),
    bottomNavigationBar: BottomAppBar(
      hasNotch: true,
      child: new Row(
        mainAxisSize: MainAxisSize.max,
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        children: <Widget>[
          IconButton(icon: Icon(Icons.menu), onPressed: () {},),
          IconButton(icon: Icon(Icons.search), onPressed: () {},),
        ],
      ),
    ),
  );
}

谢谢!

答案 1 :(得分:2)

尝试实现此修订版的代码。 FAB应该在三个选项卡上均保持不变

class BarTab extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
  home: DefaultTabController(
    length: 3,
    child: Scaffold(
      appBar: AppBar(
        bottom: TabBar(
          tabs: [
            Tab(icon: Icon(Icons.directions_car)),
            Tab(icon: Icon(Icons.directions_transit)),
            Tab(icon: Icon(Icons.directions_bike)),
          ],
        ),
        title: Text('Tabs Demo'),
      ),
      body: TabBarView(
        children: [
          Icon(Icons.audio),
          Icon(Icons.play),
          Icon(Icons.maps),
        ],
      ),

 floatingActionButton: FloatingActionButton(
 onpressed:(){},
 child: Icon(Icons.add),
),
floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
bottomNavigationBar:BottomAppBar(
 color:Colors.blue,
 hasNotch: true,
 child:Container(
height:50.0
child:Row(
  children: <Widget>[
    IconButton(
      icon: Icon(Icons.menu),
      onPressed: (){})
  ]
)
)

    ),
  ),
);
}

答案 2 :(得分:1)

2020解决方案:

BottomAppBar中不再有

hasNotch属性,但是,您可以在Scaffold中完成此操作

 bottomNavigationBar: BottomAppBar(
    shape: CircularNotchedRectangle(), //this is what creates the notch 
    color: Colors.blue,
    child: SizedBox(
      height: height * 0.1,
      width: width,
    ),
  ),
  floatingActionButton: Container(
    margin: EdgeInsets.all(10),
    width: 80.0,
    height: 80.0,
    child: FloatingActionButton(
      onPressed: () {},
      child: Icon(
        Icons.add,
        size: 25.0,
      ),
    ),
  ),
  floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked

输出:

enter image description here