Sampath Wijesinghe
Sampath Wijesinghe

Reputation: 690

Undefined name 'context' in flutter navigation

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

Upvotes: 0

Views: 2114

Answers (2)

Nithesh
Nithesh

Reputation: 204

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

Upvotes: 0

dhruvin prajapati
dhruvin prajapati

Reputation: 321

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

Upvotes: 2

Related Questions