【发布时间】:2020-03-11 18:03:42
【问题描述】:
我正在尝试制作底部导航栏,但在屏幕上左右填充。现在我用容器包装 BottomNavigationBar 并在那里添加填充。问题是BottomNavigationBar默认背景仍然包裹着所有图层,那我们可以去掉那里的背景颜色吗?
bottomNavigationBar: Container(
margin: EdgeInsets.only(left: 16, right: 16),
decoration: BoxDecoration(
color: Colors.black,
borderRadius: BorderRadius.only(
topLeft: Radius.circular(20),
topRight: Radius.circular(20)),
),
child: BottomNavigationBar(
backgroundColor: Colors.transparent,
showUnselectedLabels: true,
type: BottomNavigationBarType.fixed,
elevation: 0,
currentIndex: _currentIndex,
items: [
BottomNavigationBarItem(
icon: Icon(Icons.home), title: Text('Home')),
BottomNavigationBarItem(
icon: Icon(Icons.local_activity), title: Text('Activity')),
BottomNavigationBarItem(
icon: Icon(Icons.inbox), title: Text('Inbox')),
BottomNavigationBarItem(
icon: Icon(Icons.person), title: Text('Profile')),
],
),
),
编辑:我已经删除了脚手架和所有主题中的背景颜色,但是当您滚动项目时,您可以看到那里仍然有背景 Remove Scafold bg
编辑 2:这里是活动的代码
class App extends StatelessWidget {
final List<Widget> _children = [
Center(
child: Container(
height: 850,
color: Colors.red,
),
)
];
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
home: Scaffold(
body: _children[0],
bottomNavigationBar: Container(
margin: EdgeInsets.only(left: 16, right: 16),
decoration: BoxDecoration(
color: Colors.amber,
borderRadius: BorderRadius.only(
topLeft: Radius.circular(200), topRight: Radius.circular(200)),
),
child: BottomNavigationBar(
backgroundColor: Colors.transparent,
showUnselectedLabels: true,
type: BottomNavigationBarType.fixed,
elevation: 0,
items: [
BottomNavigationBarItem(
icon: Icon(Icons.home), title: Text('Home')),
BottomNavigationBarItem(
icon: Icon(Icons.local_activity), title: Text('Activity')),
BottomNavigationBarItem(
icon: Icon(Icons.inbox), title: Text('Inbox')),
BottomNavigationBarItem(
icon: Icon(Icons.person), title: Text('Profile')),
],
),
),
),
);
}
}
【问题讨论】:
-
它应该可以按您的预期工作。我认为你已经在你的脚手架或你使用过的任何其他包装方法上设置了背景颜色。请检查或共享整页源代码
-
我也测试过,没有问题。您可能已通过主题数据为导航栏设置颜色或在父元素上设置背景颜色
-
如果我们在列表视图中有滚动项,我们可以看到背景仍然存在
-
你肯定做错了什么。如果您需要帮助,请发布发生此问题的活动的完整代码。
-
helo @OMiShah 我已经发布了活动代码和结果截图,你能看看