I am a beginner with flutter, I had just started a few days ago. I want to go from one widget to another widget in another file. But when I use the navigator it shows an error.
I've tried to solve it using some answers to similar problems on stack overflow, but I can't solve it. Also, I am not able to understand those properly.
These are some of them:
Undefined name 'context' in flutter navigation
"take_attendance.dart"
class TakeAttendance extends StatefulWidget {
static String tag = 'take-attendance';
@override
_TakeAttendanceState createState() => _TakeAttendanceState();
}
bool colorCheck = false;
class _TakeAttendanceState extends State<TakeAttendance> {
@override
Widget build(BuildContext context) {
}
}
"home_page.dart"
this is a widget in 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);
},
),
],
)
]
),
);
}
On pressing go I want it to go to the take_attendance.dart
page.
But when using navigator this is the error that I got:
Undefined name 'context'. Try correcting the name to one that is defined, or defining the name.dart(undefined_identifier)