【问题标题】:Navigator.push opens a page BELOW TabBar but I need it to open the page fullscreenNavigator.push 在 TabBar 下方打开一个页面,但我需要它来全屏打开页面
【发布时间】:2021-10-09 05:25:11
【问题描述】:

我有一个 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),
            ),
          ),
        ),
      ),
    );
  }
}

What the screen looks like

【问题讨论】:

    标签: flutter


    【解决方案1】:

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

    见:https://stackoverflow.com/a/60372154/3407244

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-08-29
      • 1970-01-01
      • 1970-01-01
      • 2017-05-24
      • 1970-01-01
      相关资源
      最近更新 更多