PopupMenuButton 在按钮上方打开一个菜单,因此它挡住了底部栏。我找到了一种解决方法,而不是使用PopupMenuButton,尝试使用BottomAppBar 和IconButton 作为其中一个孩子,然后使用showBottomSheet,这样它就不会阻止BottomAppBar。
注意:我的大部分代码只是模仿图像布局的占位符,您需要重写大部分代码以满足您的需求。关键是使用showBottomSheet 来解决您的问题。
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
final String title;
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
bottomNavigationBar: BottomAppBar(
child: Container(
height: 70,
child: Row(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
Icon(Icons.home),
Icon(Icons.alarm),
MyMiddleIcon(),
Icon(Icons.album),
Icon(Icons.assignment_ind),
],
),
),
shape: CircularNotchedRectangle(),
color: Colors.blueGrey[50],
),
);
}
}
class MyMiddleIcon extends StatelessWidget {
@override
Widget build(BuildContext context) {
return IconButton(
icon: Icon(Icons.add),
onPressed: () {
showBottomSheet(
context: context,
builder: (context) => Container(
color: Colors.red[100],
height: 250,
width: double.infinity,
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
Icon(Icons.home),
Icon(Icons.hot_tub),
Icon(Icons.hourglass_empty),
],
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
Icon(Icons.home),
Icon(Icons.hot_tub),
Icon(Icons.hourglass_empty),
],
),
],
),
));
});
}
}