为什么我的导航器没有响应?

时间:2019-11-11 15:25:19

标签: flutter navigator

我不知道为什么我得到这么多下票...我是新来的。抱歉,造成任何误会。希望有人能最终帮助我解决我的问题。

“我的导航器”进入“设置”屏幕后将无法使用。我希望你能帮助我。非常感谢!这是代码。

这是主要的飞镖

void main() => runApp(biminda());

class biminda extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      theme: ThemeData.dark().copyWith(
          primaryColor: Color(0xFFad1457),
          scaffoldBackgroundColor: Colors.white),
      initialRoute: '/',
      routes: {
        '/': (context) => HomeScreeen(),
        '/setting': (context) => Settings(),
      },
    );
  }
}

从我的主屏幕上

Container(
              padding: EdgeInsets.fromLTRB(20, 0, 0, 30),
              child: SideButton(
                functionality: 'Settings',
                onPressed: () {
                  Navigator.push(
                    context,
                    MaterialPageRoute(
                      builder: (context) => Settings(),
                    ),
                  );
                },
              ),
            ),

我更新了容器,但没有任何改变。

Container(
              padding: EdgeInsets.fromLTRB(20, 0, 0, 30),
              child: SideButton(
                functionality: 'Settings',
                onPressed: () {
                  Navigator.of(context).push(
                    MaterialPageRoute(
                      builder: (context) => Settings(),
                    ),
                  );
                },
              ),
            ),

非常感谢!我希望这将得到解决。 :)

2 个答案:

答案 0 :(得分:0)

您没有在主菜单中声明您的setting()页面,  在MaterialApp的主目录中,删除home,将其替换为initialRoute,例如下面的代码,

MaterialApp(

//......
    initialRoute: '/',
          routes: {
            '/': (context) => HomePage(),
            '/setting': (context) => SettingsPage(), );

答案 1 :(得分:0)

请添加有关您的问题的更多详细信息,这是我根据您的代码提出的建议:

在“设置”屏幕中,您无需执行

Navigator.pop(context, MaterialPageRoute....);

只需做

Navigator.pop(context);