我试图从顶部制作AppBar幻灯片并在屏幕上显示它,然后在10秒后隐藏。
我目前正在通过显示基于布尔变量值的Appbar并且它也在工作,但是当AppBar出现时,屏幕被调整大小以适合AppBar。我希望我的屏幕保持原样,AppBar只是覆盖在屏幕上,就像横幅一样。
_showAppBar(bool val) {
setState(() {
if (val) {
_barVisible = true;
print("show");
}
else {
_barVisible = false;
print("hide");
}
});
}
Widget build(BuildContext context) {
return Theme(
data: getCurrentTheme(),
child: Scaffold(
key: _scaffoldKey,
appBar: _barVisible ? buildAppBar():null,
body: buildBody()
));
}
buildAppBar() {
Color accentColor = currentSelectedTheme == MyThemes.defaultLight ? Colors.white : getAccentColor();
return AppBar(
leading: Text(appBarTitle, style: TextStyle(color: accentColor)),
actions: <Widget>[
IconButton(
icon: Icon(
_nightMode ? Icons.lightbulb_outline : Icons.brightness_2
),
padding: EdgeInsets.fromLTRB(0.0, 0.0, 16.0, 0.0),
iconSize: 32.0,
onPressed: () => print("hi")
],
);
}
Scaffold
无法帮助您实现您的目标。请改用AppBar
中的Stack
。尝试这样的事情:
@override
Widget build(BuildContext context) {
return Theme(
data: getCurrentTheme(),,
child: Scaffold(
key: _scaffoldKey,
body: Stack(
children: <Widget>[
buildBody(),
/*Below is the new AppBar code. Without Positioned widget AppBar will fill entire screen*/
Positioned(
top: 0.0,
left: 0.0,
right: 0.0,
child: _barVisible ? buildAppBar() : Container(width: 0, height: 0,),
/*You can't put null in the above line since Stack won't allow that*/
)
],
)
),
);
}
其余代码将保持不变。如果有帮助,请告诉我!