我已将我的底部导航栏定制为浮动容器,但是单击搜索栏时我遇到了问题(如图所示)我已经签出了此POST,但所有答案都无济于事。
这是我的代码:
int _currentIndex = 0;
final List<Widget> _pages = [
FeedsPage(),
SearchPage(),
NotificationsPage(),
ProfilePage(),
AddPostPage()
];
void onTabTapped(int index) {
setState(() {
_currentIndex = index;
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: Stack(
children: <Widget>[
_pages[_currentIndex],
Positioned(
bottom: 0.0,
left: 10.0,
right: 10.0,
child: floatingBNB(),
),
Positioned(
bottom: 65.0,
left: 10.0,
right: 10.0,
child: FloatingActionButton(
backgroundColor: Color(0xffbbd1c5),
onPressed: () {
onTabTapped(4);
},
child: Icon(
Icons.add,
color: Colors.white,
),
),
),
],
),
);
}
Widget floatingBNB() {
void onTabTapped(int index) {
setState(() {
_currentIndex = index;
});
}
return Container(
margin: EdgeInsets.only(bottom: 30.0, left: 10.0, right: 10.0),
constraints: BoxConstraints.tightFor(height: 70.0),
child: Material(
borderRadius: BorderRadius.circular(35),
color: Colors.white,
elevation: 5.0,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
IconButton(
icon: Icon(
OMIcons.home,
color: Colors.black54,
size: 30.0,
),
onPressed: () {
onTabTapped(0);
}),
IconButton(
icon: Icon(
OMIcons.search,
color: Colors.black54,
size: 30.0,
),
onPressed: () {
onTabTapped(1);
}),
SizedBox(
width: 10.0,
),
IconButton(
icon: Icon(
OMIcons.notifications,
color: Colors.black54,
size: 30.0,
),
onPressed: () {
onTabTapped(2);
}),
IconButton(
icon: Icon(
OMIcons.person,
color: Colors.black54,
size: 30.0,
),
onPressed: () {
onTabTapped(3);
}),
],
),
),
);
}
}
在Scaffold
中将resizeToAvoidBottomPadding
设置为false
: