Flutter 未定义名称';上下文';在导航器中

Flutter 未定义名称';上下文';在导航器中,flutter,Flutter,我是一个初学者与颤振,我刚刚开始前几天。 我想从一个小部件转到另一个文件中的另一个小部件。 但是当我使用导航器时,它显示了一个错误 我试图用一些关于堆栈溢出的类似问题的答案来解决它,但我无法解决它。 而且,我无法正确理解这些 其中包括: “出席,达特” 课堂出勤扩展StatefulWidget{ 静态字符串标记='take Attention'; @凌驾 _TakeAttendantEstate createState()=>\u TakeAttendantEstate(); } 布尔颜色检

我是一个初学者与颤振,我刚刚开始前几天。 我想从一个小部件转到另一个文件中的另一个小部件。 但是当我使用导航器时,它显示了一个错误

我试图用一些关于堆栈溢出的类似问题的答案来解决它,但我无法解决它。 而且,我无法正确理解这些

其中包括:

“出席,达特”

课堂出勤扩展StatefulWidget{
静态字符串标记='take Attention';
@凌驾
_TakeAttendantEstate createState()=>\u TakeAttendantEstate();
}
布尔颜色检查=假;
类_takeAttendance扩展状态{
@凌驾
小部件构建(构建上下文){
}
}
“主页.省道”

这是home_page.dart中的一个小部件

Widget showPeriod(int a) {
  return Scaffold(
    appBar: new AppBar(
          title: new Text(
            "AppName",
            style: TextStyle(fontSize: 30.0, fontWeight: FontWeight.w900),
          ),
          backgroundColor: Colors.blue[800],
          actions: <Widget>[
            new Padding(
                padding: EdgeInsets.only(right: 10.0),
                child: Icon(Icons.exit_to_app)),
          ],
        ),
        drawer: new AppDrawer(),
    body: new Column(
        mainAxisAlignment: MainAxisAlignment.center,
        mainAxisSize: MainAxisSize.max,

        children: <Widget>[
            new Row(
              mainAxisAlignment: MainAxisAlignment.center,
              mainAxisSize: MainAxisSize.max,
              children: <Widget>[
              new Text("Period #$a",
            style: TextStyle(fontSize: 50.0,fontWeight: FontWeight.w400),
            )
            ],),

            new Row(
              mainAxisAlignment: MainAxisAlignment.center,
              mainAxisSize: MainAxisSize.max,
              children: <Widget>[
              new Container(
                            child: Text(
                              "<time>",
                              style: TextStyle(color: Colors.white),
                            ),
                            decoration: new BoxDecoration(
                              borderRadius: new BorderRadius.all(
                                  new Radius.circular(30.0)),
                              color: Colors.grey,
                            ),
                            padding:
                                new EdgeInsets.fromLTRB(10.0, 5.0, 10.0, 5.0),
                          ),
                          SizedBox(width: 10.0),
                          new Container(
                            child: Text(
                              "<Class>",
                              style: TextStyle(color: Colors.white),
                            ),
                            decoration: new BoxDecoration(
                              borderRadius: new BorderRadius.all(
                                  new Radius.circular(30.0)),
                              color: Colors.grey,
                            ),
                            padding:
                                new EdgeInsets.fromLTRB(10.0, 5.0, 10.0, 5.0),
                          ),


            ],),
             new Padding(
                        padding: EdgeInsets.only(left: 10.0, top: 10.0),
                        child: new Row(
                          mainAxisAlignment: MainAxisAlignment.center,
                          mainAxisSize: MainAxisSize.max,
                          children: <Widget>[
                            new Container(
                              child: Text(
                                "An imaginary subject.",
                                style: TextStyle(color: Colors.white),
                              ),
                              decoration: new BoxDecoration(
                                borderRadius: new BorderRadius.all(
                                    new Radius.circular(30.0)),
                                color: Colors.grey,
                              ),
                              padding:
                                  new EdgeInsets.fromLTRB(10.0, 5.0, 10.0, 5.0),
                            ),
                          ],
                        )),

                        SizedBox(height: 40.0,),

                        new Row(
                          mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                          mainAxisSize: MainAxisSize.max,
                          children: <Widget>[
                            new RaisedButton(
                              child: const Text('GO!'),
                              color: Colors.redAccent,
                              elevation: 4.0,
                              splashColor: Colors.red,
                              onPressed: () {
                                // Perform some action
                                  Navigator.of(context).pushNamed(TakeAttendance.tag);
                                  //Navigator.push(context,takeAttendance());
                              },
                            ),

                            new RaisedButton(
                              child: const Text('Cancel'),
                              color: Colors.blueAccent,
                              elevation: 4.0,
                              splashColor: Colors.blue[200],
                              onPressed: () {
                                // Perform some action
                                //Navigator.pop(context);
                              },
                            ),
                          ],
                        )

          ]


        ),
  );
}
Widget showPeriod(int a){
返回脚手架(
appBar:新的appBar(
标题:新文本(
“AppName”,
样式:TextStyle(fontSize:30.0,fontWeight:fontWeight.w900),
),
背景颜色:颜色。蓝色[800],
行动:[
新填料(
填充:仅限边缘设置(右侧:10.0),
子:图标(图标。退出到应用程序)),
],
),
抽屉:新的AppDrawer(),
正文:新栏目(
mainAxisAlignment:mainAxisAlignment.center,
mainAxisSize:mainAxisSize.max,
儿童:[
新行(
mainAxisAlignment:mainAxisAlignment.center,
mainAxisSize:mainAxisSize.max,
儿童:[
新文本(“句号#$a”,
样式:TextStyle(fontSize:50.0,fontWeight:fontWeight.w400),
)
],),
新行(
mainAxisAlignment:mainAxisAlignment.center,
mainAxisSize:mainAxisSize.max,
儿童:[
新容器(
子:文本(
"",
样式:TextStyle(颜色:Colors.white),
),
装饰:新盒子装饰(
borderRadius:新建borderRadius.all(
新半径。圆形(30.0)),
颜色:颜色。灰色,
),
衬垫:
来自LTRB(10.0,5.0,10.0,5.0)的新边缘集,
),
尺寸箱(宽度:10.0),
新容器(
子:文本(
"",
样式:TextStyle(颜色:Colors.white),
),
装饰:新盒子装饰(
borderRadius:新建borderRadius.all(
新半径。圆形(30.0)),
颜色:颜色。灰色,
),
衬垫:
来自LTRB(10.0,5.0,10.0,5.0)的新边缘集,
),
],),
新填料(
填充:仅限边缘设置(左侧:10.0,顶部:10.0),
孩子:新的一排(
mainAxisAlignment:mainAxisAlignment.center,
mainAxisSize:mainAxisSize.max,
儿童:[
新容器(
子:文本(
“想象中的主体。”,
样式:TextStyle(颜色:Colors.white),
),
装饰:新盒子装饰(
borderRadius:新建borderRadius.all(
新半径。圆形(30.0)),
颜色:颜色。灰色,
),
衬垫:
来自LTRB(10.0,5.0,10.0,5.0)的新边缘集,
),
],
)),
尺寸箱(高度:40.0,),
新行(
mainAxisAlignment:mainAxisAlignment.space,
mainAxisSize:mainAxisSize.max,
儿童:[
新升起的按钮(
child:const Text('GO!'),
颜色:Colors.redAccent,
标高:4.0,
颜色:颜色。红色,
已按下:(){
//执行一些操作
Navigator.of(context.pushNamed)(takeAttention.tag);
//Navigator.push(上下文,takeAttention());
},
),
新升起的按钮(
子项:常量文本(“取消”),
颜色:Colors.blueAccent,
标高:4.0,
splashColor:Colors.blue[200],
已按下:(){
//执行一些操作
//Navigator.pop(上下文);
},
),
],
)
]
),
);
}
按go键时,我希望它转到
take_Attention.dart
页面

但在使用navigator时,我得到的错误是:

未定义的名称“上下文”。 尝试将名称更正为已定义的名称,或定义名称.dart(未定义的\u标识符)


您的“上下文”在上没有导航器实例
Widget showPeriod(int a) {
  return Scaffold(
    appBar: new AppBar(
          title: new Text(
            "AppName",
            style: TextStyle(fontSize: 30.0, fontWeight: FontWeight.w900),
          ),
          backgroundColor: Colors.blue[800],
          actions: <Widget>[
            new Padding(
                padding: EdgeInsets.only(right: 10.0),
                child: Icon(Icons.exit_to_app)),
          ],
        ),
        drawer: new AppDrawer(),
    body: new Column(
        mainAxisAlignment: MainAxisAlignment.center,
        mainAxisSize: MainAxisSize.max,

        children: <Widget>[
            new Row(
              mainAxisAlignment: MainAxisAlignment.center,
              mainAxisSize: MainAxisSize.max,
              children: <Widget>[
              new Text("Period #$a",
            style: TextStyle(fontSize: 50.0,fontWeight: FontWeight.w400),
            )
            ],),

            new Row(
              mainAxisAlignment: MainAxisAlignment.center,
              mainAxisSize: MainAxisSize.max,
              children: <Widget>[
              new Container(
                            child: Text(
                              "<time>",
                              style: TextStyle(color: Colors.white),
                            ),
                            decoration: new BoxDecoration(
                              borderRadius: new BorderRadius.all(
                                  new Radius.circular(30.0)),
                              color: Colors.grey,
                            ),
                            padding:
                                new EdgeInsets.fromLTRB(10.0, 5.0, 10.0, 5.0),
                          ),
                          SizedBox(width: 10.0),
                          new Container(
                            child: Text(
                              "<Class>",
                              style: TextStyle(color: Colors.white),
                            ),
                            decoration: new BoxDecoration(
                              borderRadius: new BorderRadius.all(
                                  new Radius.circular(30.0)),
                              color: Colors.grey,
                            ),
                            padding:
                                new EdgeInsets.fromLTRB(10.0, 5.0, 10.0, 5.0),
                          ),


            ],),
             new Padding(
                        padding: EdgeInsets.only(left: 10.0, top: 10.0),
                        child: new Row(
                          mainAxisAlignment: MainAxisAlignment.center,
                          mainAxisSize: MainAxisSize.max,
                          children: <Widget>[
                            new Container(
                              child: Text(
                                "An imaginary subject.",
                                style: TextStyle(color: Colors.white),
                              ),
                              decoration: new BoxDecoration(
                                borderRadius: new BorderRadius.all(
                                    new Radius.circular(30.0)),
                                color: Colors.grey,
                              ),
                              padding:
                                  new EdgeInsets.fromLTRB(10.0, 5.0, 10.0, 5.0),
                            ),
                          ],
                        )),

                        SizedBox(height: 40.0,),

                        new Row(
                          mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                          mainAxisSize: MainAxisSize.max,
                          children: <Widget>[
                            new RaisedButton(
                              child: const Text('GO!'),
                              color: Colors.redAccent,
                              elevation: 4.0,
                              splashColor: Colors.red,
                              onPressed: () {
                                // Perform some action
                                  Navigator.of(context).pushNamed(TakeAttendance.tag);
                                  //Navigator.push(context,takeAttendance());
                              },
                            ),

                            new RaisedButton(
                              child: const Text('Cancel'),
                              color: Colors.blueAccent,
                              elevation: 4.0,
                              splashColor: Colors.blue[200],
                              onPressed: () {
                                // Perform some action
                                //Navigator.pop(context);
                              },
                            ),
                          ],
                        )

          ]


        ),
  );
}
Widget showPeriod(int a) {
  return Scaffold(
    appBar: new AppBar(
      title: new Text(
        "Hajar",
        style: TextStyle(fontSize: 30.0, fontWeight: FontWeight.w900),
      ),
      backgroundColor: Colors.blue[800],
      actions: <Widget>[
        new Padding(
            padding: EdgeInsets.only(right: 10.0),
            child: Icon(Icons.exit_to_app)),
      ],
    ),
    drawer: new AppDrawer(),
    body: MyPageBody(),
  );
}


class MyPage extends StatelessWidget {

  @override
  Widget build(BuildContext context) {
    return new Column(
        mainAxisAlignment: MainAxisAlignment.center,
        mainAxisSize: MainAxisSize.max,
        children: <Widget>[
          new Row(
            mainAxisAlignment: MainAxisAlignment.center,
            mainAxisSize: MainAxisSize.max,
            children: <Widget>[
              new Text(
                "Period #$a",
                style: TextStyle(fontSize: 50.0, fontWeight: FontWeight.w400),
              )
            ],
          ),
          new Row(
            mainAxisAlignment: MainAxisAlignment.center,
            mainAxisSize: MainAxisSize.max,
            children: <Widget>[
              new Container(
                child: Text(
                  "<time>",
                  style: TextStyle(color: Colors.white),
                ),
                decoration: new BoxDecoration(
                  borderRadius: new BorderRadius.all(new Radius.circular(30.0)),
                  color: Colors.grey,
                ),
                padding: new EdgeInsets.fromLTRB(10.0, 5.0, 10.0, 5.0),
              ),
              SizedBox(width: 10.0),
              new Container(
                child: Text(
                  "<Class>",
                  style: TextStyle(color: Colors.white),
                ),
                decoration: new BoxDecoration(
                  borderRadius: new BorderRadius.all(new Radius.circular(30.0)),
                  color: Colors.grey,
                ),
                padding: new EdgeInsets.fromLTRB(10.0, 5.0, 10.0, 5.0),
              ),
            ],
          ),
          new Padding(
              padding: EdgeInsets.only(left: 10.0, top: 10.0),
              child: new Row(
                mainAxisAlignment: MainAxisAlignment.center,
                mainAxisSize: MainAxisSize.max,
                children: <Widget>[
                  new Container(
                    child: Text(
                      "An imaginary subject.",
                      style: TextStyle(color: Colors.white),
                    ),
                    decoration: new BoxDecoration(
                      borderRadius:
                          new BorderRadius.all(new Radius.circular(30.0)),
                      color: Colors.grey,
                    ),
                    padding: new EdgeInsets.fromLTRB(10.0, 5.0, 10.0, 5.0),
                  ),
                ],
              )),
          SizedBox(
            height: 40.0,
          ),
          new Row(
            mainAxisAlignment: MainAxisAlignment.spaceEvenly,
            mainAxisSize: MainAxisSize.max,
            children: <Widget>[
              new RaisedButton(
                child: const Text('GO!'),
                color: Colors.redAccent,
                elevation: 4.0,
                splashColor: Colors.red,
                onPressed: () {
                  // Perform some action
                  Navigator.of(context).pushNamed(TakeAttendance.tag);
                  //Navigator.push(context,takeAttendance());
                },
              ),
              new RaisedButton(
                child: const Text('Cancel'),
                color: Colors.blueAccent,
                elevation: 4.0,
                splashColor: Colors.blue[200],
                onPressed: () {
                  // Perform some action
                  //Navigator.pop(context);
                },
              ),
            ],
          )
        ]);
  }
}