首页 > 解决方案 > 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),
            ),
          ),
        ),
      ),
    );
  }
}

屏幕是什么样子的

标签: flutter

解决方案


尝试使用Navigator.of(context, rootNavigator: true).push(...).

请参阅:https ://stackoverflow.com/a/60372154/3407244


推荐阅读