flutter - Navigator.push 在 TabBar 下方打开一个页面,但我需要它来全屏打开页面
问题描述
我有一个 TabBar,在其中一个选项卡中有重定向到页面的按钮。当我单击按钮时,它应该只是打开页面。但是,单击时,它会打开 TabBar 下方的页面,如下图所示。我怎样才能使页面在整个页面上打开?
我为我的按钮制作了一个自定义小部件:
class CalendarButton extends StatelessWidget {
String bgImage = "";
String title = "";
String page = "";
CalendarButton(
{required this.bgImage, required this.title, required this.page});
@override
Widget build(BuildContext context) {
return Container(
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.bottomCenter,
colors: [
Colors.black.withOpacity(.3),
Colors.black.withOpacity(.3),
],
),
),
child: Ink.image(
image: AssetImage(
bgImage,
),
fit: BoxFit.cover,
child: InkWell(
onTap: () {
if (page == 'FP') {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => FP(),
),
);
} else if (page == 'MS') {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => MS(),
),
);
} else if (page == 'HS') {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => HS(),
),
);
} else if (page == 'Year') {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => Year(),
),
);
}
},
child: Center(
child: Text(
title,
style: TextStyle(
color: Colors.white,
fontSize: 30,
fontWeight: FontWeight.bold),
),
),
),
),
);
}
}
解决方案
尝试使用Navigator.of(context, rootNavigator: true).push(...)
.
推荐阅读
- python - 从 Matplotlib 地图中提取 RGBA
- python - 尝试使用用户输入作为起点从python 3范围内的列表中提取一定数量的数字
- emacs - 在 elisp 中传递函数参数
- python-3.x - 我无法启动 Python 脚本
- javascript - 获取'未捕获的类型错误:无法读取未定义的属性'帮助者''
- regex - 如何从彭博导入价格?
- javascript - 仅调用一次时,函数被执行两次
- python - os.startfile() 没有打开 .docx 文件
- android - RelativeLayout 有效,而 ConstraintLayout 失败
- tvos - tvOS 13 上的画中画