You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Flutter页面导航无响应求助:Navigator.push点击无跳转

Flutter页面导航无跳转问题解决

核心问题

你的跳转页面Submitid中错误嵌套了MaterialApp组件。Flutter应用里只能有一个根MaterialApp,它负责管理全局导航栈。当你在跳转页面重复创建MaterialApp时,会生成独立的导航上下文,原页面的Navigator.push无法将页面推入正确的栈,导致点击按钮无跳转且无报错。

解决方案

修改Submitid页面,移除多余的MaterialApp,直接返回Scaffold组件:

修正后的submit_id.dart代码

import 'package:flutter/material.dart';

class Submitid extends StatefulWidget {
  const Submitid({Key? key}) : super(key: key);

  @override
  State<Submitid> createState() => _SubmitidState();
}

class _SubmitidState extends State<Submitid> {
  @override
  Widget build(BuildContext context) {
    // 移除外层MaterialApp,直接返回Scaffold
    return Scaffold(
      backgroundColor: Colors.black,
      appBar: AppBar(
        title: Text(
          'Bits mess',
          style: TextStyle(
            fontWeight: FontWeight.bold,
            fontSize: 20,
            letterSpacing: 5,
          ),
        ),
        backgroundColor: Colors.black,
        centerTitle: true,
      ),
      // 可添加页面其他内容
    );
  }
}

额外验证点(若问题仍存在)

  • 确认按钮的context属于根MaterialApp的上下文:你的主页面中按钮位于MaterialApp的home层级内,上下文有效,此问题当前代码不存在。
  • 检查Submitid类是否正确导入主页面:你的代码已完成导入,此步骤无问题。

内容的提问来源于stack exchange,提问作者Archit_0410

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.17 11:25:24