myn*_*eis 3 android floating-action-button flutter bottomnavigationview
我有底部导航栏,中心项目如下图所示:
如何在Flutter中实现这样的事情?
我发现我放入BottomNavigatonBarItem的每个图标都符合导航栏的界限.但我需要把它挂在上面.
您可以Stack在彼此的顶部显示小部件.结合属性overflow:Overflow.visible和符合您需求的对齐方式.
以下示例将实现图片中的内容:水平居中的浮动按钮,顶部与底部条对齐.
return new Scaffold(
bottomNavigationBar: new Stack(
overflow: Overflow.visible,
alignment: new FractionalOffset(.5, 1.0),
children: [
new Container(
height: 40.0,
color: Colors.red,
),
new Padding(
padding: const EdgeInsets.only(bottom: 12.0),
child: new FloatingActionButton(
notchMargin: 24.0,
onPressed: () => print('hello world'),
child: new Icon(Icons.arrow_back),
),
),
],
),
);
Run Code Online (Sandbox Code Playgroud)
您也可以使用 FloatingActionButtonLocation 和 Expanded 小部件来执行此操作,如下所示:
Widget build(BuildContext context) {
return new Scaffold(
appBar: new AppBar(
title: new Text(widget.title),
),
body: _buildTodoList(),
floatingActionButton: new FloatingActionButton(
onPressed: _pushAddTodoScreen,
tooltip: 'Increment',
child: new Icon(Icons.add),
elevation: 4.0,
),
bottomNavigationBar: BottomAppBar(
child: new Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Expanded(child: IconButton(icon: Icon(Icons.home)),),
Expanded(child: IconButton(icon: Icon(Icons.show_chart)),),
Expanded(child: new Text('')),
Expanded(child: IconButton(icon: Icon(Icons.tab)),),
Expanded(child: IconButton(icon: Icon(Icons.settings)),),
],
),
),
floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
);
}
Run Code Online (Sandbox Code Playgroud)
预览:

谷歌最近添加了一个叫做的东西BottomAppBar,它提供了一种更好的方法来做到这一点。只需BottomAppBar在脚手架中添加,创建一个导航 FAB,如果您希望它有文本,则向 FAB 添加一个标签。创建与此类似的结果:https : //cdn-images-1.medium.com/max/1600/1*SEYUo6sNrW0RoKxyrYCqbg.png。
Widget build(BuildContext context) {
return new Scaffold(
appBar: AppBar(title: const Text('Tasks - Bottom App Bar')),
floatingActionButton: FloatingActionButton.extended(
elevation: 4.0,
icon: const Icon(Icons.add),
label: const Text('Add a task'),
onPressed: () {},
),
floatingActionButtonLocation:
FloatingActionButtonLocation.centerDocked,
bottomNavigationBar: BottomAppBar(
hasNotch: false,
child: new Row(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
IconButton(
icon: Icon(Icons.menu),
onPressed: () {},
),
IconButton(
icon: Icon(Icons.search),
onPressed: () {},
)
],
),
),
);
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7261 次 |
| 最近记录: |