首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何向TabBar添加凹槽以将FloatingActionButton放入其中

如何向TabBar添加凹槽以将FloatingActionButton放入其中
EN

Stack Overflow用户
提问于 2018-08-16 23:54:14
回答 3查看 1.3K关注 0票数 4

我想在TabBar中创建一个凹口来放置FloatingActionBottom,但是我不知道怎么做。

我在纪录片和互联网上什么也没找到。

EN

回答 3

Stack Overflow用户

发布于 2018-08-17 00:54:43

对于这种用户界面,可以使用底部应用程序栏。BottomAppBar的hasNotch属性必须为true。

这会给你带来我想要的结果

代码语言:javascript
复制
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: () {},),
        ],
      ),
    ),
  );
}

谢谢!

票数 3
EN

Stack Overflow用户

发布于 2018-08-17 00:47:24

尝试实现代码的这个修订版。FAB应该在三个选项卡中持续存在

代码语言:javascript
复制
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
EN

Stack Overflow用户

发布于 2020-07-25 04:28:18

2020年解决方案:

BottomAppBar中不再有hasNotch属性,但您可以在Scaffold中执行此操作

代码语言:javascript
复制
 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

输出:

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51881025

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档