Flutter 带有垂直打开菜单的AppBar
我正在构建一个颤振应用程序,我正在尝试在AppBar中添加一个菜单,当你按下标题时,它会垂直打开。我尝试了很多方法,但没有一种给我我想要的结果。。 我有两个主要问题:Flutter 带有垂直打开菜单的AppBar,flutter,dart,Flutter,Dart,我正在构建一个颤振应用程序,我正在尝试在AppBar中添加一个菜单,当你按下标题时,它会垂直打开。我尝试了很多方法,但没有一种给我我想要的结果。。 我有两个主要问题: 当我展开菜单时,它会在屏幕中推送小部件,而不是覆盖它们(如抽屉小部件) 我不知道如何放置菜单的列表元素,因为AppBar小部件中没有子属性 这是我的密码: class CustomAppBar extends StatefulWidget implements PreferredSizeWidget { final Strin
class CustomAppBar extends StatefulWidget implements PreferredSizeWidget {
final String screenTitle;
final double height;
CustomAppBar({this.screenTitle, @required this.height, Key key})
: super(key: key);
@override
_CustomAppBarState createState() => _CustomAppBarState();
Size get preferredSize {
return new Size.fromHeight(300);
}
}
class _CustomAppBarState extends State<CustomAppBar> {
bool selected = false;
@override
void initState() {
super.initState();
}
@override
Widget build(BuildContext context) {
return Container(
child: Stack(
overflow: Overflow.clip,
alignment: Alignment.topCenter,
children: <Widget>\[
AnimatedContainer(
duration: Duration(milliseconds: 1000),
curve: Curves.easeInOutQuad,
alignment: Alignment.bottomCenter,
height: selected ? 300 : 100,
child: Container(
height: 300,
width: double.infinity,
child: AppBar(
shape: CustomShapeBorder(),
title: Center(
child: GestureDetector(
onTap: () {
setState(() {
selected = !selected;
});
},
child: Text('STYLE')),
),
),
),
)
\],
),
);
}
@override
Size get preferredSize => Size.fromHeight(widget.height);
}
class CustomShapeBorder extends ContinuousRectangleBorder {
@override
Path getOuterPath(Rect rect, {TextDirection textDirection}) {
final doubl[![enter image description here][1]][1]e innerCircleRadius = 130.0;
Path path = Path();
path.lineTo(0, rect.height);
path.quadraticBezierTo(rect.width / 2 - (innerCircleRadius / 2) - 30,
rect.height + 15, rect.width / 2 - 75, rect.height + 50);
path.cubicTo(
rect.width / 2 - 40,
rect.height + innerCircleRadius - 40,
rect.width / 2 + 40,
rect.height + innerCircleRadius - 40,
rect.width / 2 + 75,
rect.height + 50);
path.quadraticBezierTo(rect.width / 2 + (innerCircleRadius / 2) + 30,
rect.height + 15, rect.width, rect.height);
path.lineTo(rect.width, 0.0);
path.close();
return path;
}
}
类CustomAppBar扩展StatefulWidget实现PreferredSizeWidget{
最终字符串屏幕标题;
最终双倍高度;
CustomAppBar({this.screenTitle,@required this.height,Key})
:super(key:key);
@凌驾
_CustomAppBarState createState()=>\u CustomAppBarState();
大小获取首选大小{
返回新尺寸。fromHeight(300);
}
}
类_CustomAppBarState扩展状态{
bool selected=false;
@凌驾
void initState(){
super.initState();
}
@凌驾
小部件构建(构建上下文){
返回容器(
子:堆栈(
溢出:overflow.clip,
对齐:alignment.topCenter,
儿童:\[
动画容器(
持续时间:持续时间(毫秒:1000),
曲线:Curves.easeInOutQuad,
对齐:对齐.bottomCenter,
高度:已选择?300:100,
子:容器(
身高:300,
宽度:double.infinity,
孩子:AppBar(
形状:CustomShapeOrder(),
标题:中心(
儿童:手势检测器(
onTap:(){
设置状态(){
选中=!选中;
});
},
子项:文本(“样式”),
),
),
),
)
\],
),
);
}
@凌驾
Size get preferredSize=>Size.fromHeight(widget.height);
}
类CustomShapeOrder扩展了ContinuousRectangleBorder{
@凌驾
路径getOuterPath(Rect Rect,{TextDirection TextDirection}){
最终doubl[![在此输入图像描述][1][1]e innerCircleRadius=130.0;
路径=路径();
lineTo路径(0,直线高度);
路径二次Bezierto(矩形宽度/2-(内圆/2)-30,
垂直高度+15,垂直宽度/2-75,垂直高度+50);
path.cubicTo(
矩形宽度/2-40,
直线高度+内环高度-40,
矩形宽度/2+40,
直线高度+内环高度-40,
矩形宽度/2+75,
垂直高度+50);
路径二次Bezierto(矩形宽度/2+(内圆/2)+30,
垂直高度+15,垂直宽度,垂直高度);
path.lineTo(rect.width,0.0);
path.close();
返回路径;
}
}
抽屉(
//向抽屉添加列表视图。这确保用户可以滚动
//如果没有足够的垂直线,请通过抽屉中的选项
//空间适合所有东西。
子:ListView(
//重要提示:从ListView中删除任何填充。
填充:EdgeInsets.zero,
儿童:[
抽屉阅读器(
子项:文本(“抽屉标题”),
装饰:盒子装饰(
颜色:颜色,蓝色,
),
),
列表砖(
标题:文本(“项目1”),
onTap:(){
//更新应用程序的状态。
// ...
},
),
列表砖(
标题:文本(“项目2”),
onTap:(){
//更新应用程序的状态。
// ...
},
),
],
),
);
我建议在其中使用和构建菜单小部件。您可以使用。这是一个简单的例子。实际上我想让菜单从上到下展开@阿比翁47
Drawer(
// Add a ListView to the drawer. This ensures the user can scroll
// through the options in the drawer if there isn't enough vertical
// space to fit everything.
child: ListView(
// Important: Remove any padding from the ListView.
padding: EdgeInsets.zero,
children: <Widget>[
DrawerHeader(
child: Text('Drawer Header'),
decoration: BoxDecoration(
color: Colors.blue,
),
),
ListTile(
title: Text('Item 1'),
onTap: () {
// Update the state of the app.
// ...
},
),
ListTile(
title: Text('Item 2'),
onTap: () {
// Update the state of the app.
// ...
},
),
],
),
);