[英]How to overlap a widget with a custom appbar
I want to achieve an effect similar to this one:我想达到类似于这个的效果:
Here's what I have: (Blue container is hidden below the appBar)这是我所拥有的:(蓝色容器隐藏在 appBar 下方)
And this is my current code:这是我当前的代码:
Widget build(BuildContext context) {
return Scaffold(
appBar: GradesAppBar(
title: "Grades",
gradientBegin: Colors.red[200],
gradientEnd: Colors.red,
),
body: Stack(
fit: StackFit.expand,
overflow: Overflow.visible,
children: <Widget>[
Positioned(
top: -20,
left: MediaQuery.of(context).size.width / 2 - 150,
child: Container(
color: Colors.blue,
width: 300,
height: 60,
),
),
],
),
);
}
The GradesAppBar is a Container with boxShadow, borderRadius and gradient decoration. GradesAppBar 是一个带有 boxShadow、borderRadius 和渐变装饰的容器。
When you're using stack to achieve this UI approach you should remove the AppBar and make it like this :-当您使用堆栈来实现这种 UI 方法时,您应该删除AppBar并使其像这样:-
Widget build(BuildContext context) {
return Scaffold(
body: Stack(
alignment: Alignment.center,
fit: StackFit.expand,
overflow: Overflow.visible,
children: <Widget>[
GradesAppBar(
title: "Grades",
gradientBegin: Colors.red[200],
gradientEnd: Colors.red,
),
Positioned(
top: -20,
left: MediaQuery.of(context).size.width / 2 - 150,
child: Container(
color: Colors.blue,
width: 300,
height: 60,
),
),
],
),
);
}
The most important thing;最重要的事情; if your
GradesAppBar
extends PreferredSizeWidget
I think you should replace it with Container
and give it some cool decorations as you want :")如果您的
GradesAppBar
扩展了PreferredSizeWidget
我认为您应该将其替换为Container
并根据需要给它一些很酷的装饰:")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.