Why do we need to provide the context in MaterialPageRoute when the build method of the widget is also taking the context?

72 Views Asked by At

Why do we need to provide the context in MaterialPageRoute when the build method of the widget is also taking the context?

onPressed: () {
              Navigator.of(context).push(
                MaterialPageRoute(builder: (context) {
                  return Scaffold(
                    appBar: AppBar(
                      title: Text("Second Route"),
                    ),
                    body: Center(
                      child: RaisedButton(
                        onPressed: () {
                          Navigator.pop(context);
                        },
                        child: Text('Go back!'),
                      ),
                    ),
                  );
                }),
              );
            },
0

There are 0 best solutions below