Undefined name 'context' in flutter naviga

2019-08-21 09:52发布

I want to navigate into one page to another an I used following code to that

Create route

final routes = <String,WidgetBuilder> {
   DashboardIesl.tag : (context)=>DashboardIesl()
};

navigation to button click

onPressed: () {
  Navigator.push(context, new MaterialPageRoute(
    builder: (context) => new DashboardIesl()
  ));
},

It gives the error message as follows

Undefined name 'context'.

2条回答
兄弟一词,经得起流年.
2楼-- · 2019-08-21 10:41

You have to write onPressed() with in the class.

查看更多
家丑人穷心不美
3楼-- · 2019-08-21 10:50

please show me more code,context is only available in statefull widgets,

onPressed: () {  Navigator.push(
context,
MaterialPageRoute(builder: (context) => DashboardIesl()),  );}

I think this will help you

查看更多
登录 后发表回答