Undefined name 'context' in flutter navigation

时光总嘲笑我的痴心妄想 提交于 2019-12-13 04:09:26

问题


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'.


回答1:


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




回答2:


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



来源:https://stackoverflow.com/questions/55334575/undefined-name-context-in-flutter-navigation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!