问题描述
我正在尝试实现以下内容,
Im trying to achieve something like the following,
我很陌生,所以我不知道。
我需要一个自定义的AppBar,其中包含抽屉和操作,但排列方式与图像类似。
I'm very new to flutter so I couldn't figure it out.I need a custom AppBar with drawer and actions but arranged like the image.
我在标题小部件中尝试了StackView
I tried a StackView in the title widget
appBar: AppBar(
title: Stack(
children: <Widget>[
Container(
width: double.infinity,
color: CustomColors.accentColor,
),
Text(
'Title',
style: TextStyle(fontSize: 22.0, color: CustomColors.primaryDark),
),
],
),
),
但是我得到了这样的东西
But I get something like this
有人可以帮我吗?谢谢。
Can someone help me out? Thank you.
推荐答案
正如我在评论中提到的那样,您可以创建一个自定义窗口小部件,如附加的图像,有很多方法为此,这只是一个示例:
As I mentioned in the comment , you can create a Custom widget like your Image attached, there are many ways to do it, this is just an example :
class CustomBarWidget extends StatelessWidget {
GlobalKey<ScaffoldState> _scaffoldKey = GlobalKey();
@override
Widget build(BuildContext context) {
return Scaffold(
key: _scaffoldKey,
body: Container(
height: 160.0,
child: Stack(
children: <Widget>[
Container(
color: Colors.red,
width: MediaQuery.of(context).size.width,
height: 100.0,
child: Center(
child: Text(
"Home",
style: TextStyle(color: Colors.white, fontSize: 18.0),
),
),
),
Positioned(
top: 80.0,
left: 0.0,
right: 0.0,
child: Container(
padding: EdgeInsets.symmetric(horizontal: 20.0),
child: DecoratedBox(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(1.0),
border: Border.all(
color: Colors.grey.withOpacity(0.5), width: 1.0),
color: Colors.white),
child: Row(
children: [
IconButton(
icon: Icon(
Icons.menu,
color: Colors.red,
),
onPressed: () {
print("your menu action here");
_scaffoldKey.currentState.openDrawer();
},
),
Expanded(
child: TextField(
decoration: InputDecoration(
hintText: "Search",
),
),
),
IconButton(
icon: Icon(
Icons.search,
color: Colors.red,
),
onPressed: () {
print("your menu action here");
},
),
IconButton(
icon: Icon(
Icons.notifications,
color: Colors.red,
),
onPressed: () {
print("your menu action here");
},
),
],
),
),
),
)
],
),
),
);
}
}
有关更多信息,我写了一篇关于如何可以自定义 AppBar
:
For more information, I wrote an article about how we can customize the AppBar
:https://medium.com/flutter-community/flutter-increase-the-power-of-your-appbar-sliverappbar-c4f67c4e076f
这篇关于自定义AppBar颤动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!