到目前为止,我的BottomNavigationBar
看起来还不错(而且很简单),但是鉴于我只有2件物品,我希望将它们放得更近一些(也许在右边),因此更容易达到。我怎么做?有做这项工作的财产吗?也许在BottomNavigationBar
主题内?
这是现在的样子:
bottomNavigationBar: BottomNavigationBar(
items: <BottomNavigationBarItem>[
BottomNavigationBarItem(
icon: Icon(Icons.account_circle),
title: Text('Personal Data'),
),
BottomNavigationBarItem(
icon: Icon(Icons.payment),
title: Text('Contracts'),
),
],
currentIndex: _selectedIndex,
selectedItemColor: Colors.orange,
onTap: _onItemTapped,
),
答案 0 :(得分:1)
在检查BottomNavigationBar的源代码时,由于此行,因此似乎不太容易实现:
Widget _createContainer(List<Widget> tiles) {
return DefaultTextStyle.merge(
overflow: TextOverflow.ellipsis,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: tiles,
),
);
}
它在类中的私有函数中。意味着要更改包含图块的行的mainAxisAlignment属性,必须重新创建整个类。
答案 1 :(得分:0)
@override
Widget build(BuildContext context) {
return Scaffold(
bottomNavigationBar: Theme(
data: Theme.of(context).copyWith(
canvasColor: Color.fromRGBO(255, 255, 255, 0),
primaryColor: Colors.red,
textTheme: Theme.of(context).textTheme.copyWith(
caption: TextStyle(
color: Colors
.white))),
child: Container(
color: Colors.black,
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 40),
child: BottomNavigationBar(
showSelectedLabels: false,
showUnselectedLabels: false,
type: BottomNavigationBarType.fixed,
currentIndex: 0,
items: [
BottomNavigationBarItem(
icon: Icon(Icons.home),
title: Text(''),
),
BottomNavigationBarItem(
icon: Icon(Icons.search),
title: Text(''),
),
BottomNavigationBarItem(
icon: Icon(Icons.favorite_border),
title: Text(''),
),
BottomNavigationBarItem(
icon: Icon(
Icons.folder_open,
),
title: Text(''),
)
],
),
),
),
),
);