我想用iconButton验证我的颤动表单,然后转到主页。但是我无法将按钮与我要显示的页面链接

时间:2019-06-08 11:27:25

标签: flutter flutter-dependencies

我写了一些显示表单的代码。提交按钮是IconButton类型。我想通过单击进入应用程序的主页,但这会返回一个错误。

这是扑扑的形式

Container(
              child: Row(
                mainAxisAlignment: MainAxisAlignment.end,
                children: <Widget>[
                  IconButton(
                    iconSize: 80.0,
                    icon: Image.asset("images/send.png"),
                    onPressed: () {}

我希望通过单击或按下

来链接“提交”按钮

1 个答案:

答案 0 :(得分:0)

要从一页路由到另一页,您需要在materialapp小部件中添加路由。以下示例:

MaterialApp(
  home: Firstpage(),
  routes: <String,WidgetBuilder>{
    "/SecondPage": (BuildContext context) => new SecondScreen()
  }  
) 

然后在您的代码上简单地输入:

Container(
          child: Row(
            mainAxisAlignment: MainAxisAlignment.end,
            children: <Widget>[
              IconButton(
                iconSize: 80.0,
                icon: Image.asset("images/send.png"),
                onPressed: () {
                     Navigator.of(context).pushNamed("/SecondPage")
               }
           )
) 

希望这会有所帮助。