如何让showModalBottomSheet不覆盖bottomNavigationBar
时间: 2024-01-25 21:02:14 浏览: 241
要在Flutter中使用showModalBottomSheet而不覆盖bottomNavigationBar,您可以将它放在一个Scaffold中,并将其放在Scaffold的底部。这样,bottomNavigationBar将保持可见,并且showModalBottomSheet将显示在其上方。
以下是一个示例代码:
```dart
class MyPage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('My App'),
),
body: Center(
child: RaisedButton(
child: Text('Show Modal Bottom Sheet'),
onPressed: () {
showModalBottomSheet(
context: context,
builder: (BuildContext context) {
return Container(
height: 200,
child: Center(
child: Text('Modal Bottom Sheet'),
),
);
},
);
},
),
),
bottomNavigationBar: BottomNavigationBar(
items: [
BottomNavigationBarItem(
icon: Icon(Icons.home),
title: Text('Home'),
),
BottomNavigationBarItem(
icon: Icon(Icons.settings),
title: Text('Settings'),
),
],
),
);
}
}
```
在这个示例中,我们在Scaffold的底部放置了bottomNavigationBar,并在中间添加了一个RaisedButton来触发showModalBottomSheet。当我们点击按钮时,showModalBottomSheet将显示在bottomNavigationBar的上方,而不是覆盖它。
阅读全文
相关推荐


















