Transitioning from one page to another – Flutter

  android, flutter, mobile-application

So, I have got a simple single page app. I created a checkbox on that page to transition to another page when the checkbox is clicked. However I get an error with the onChanged parameter of the checkbox. It is as follows:

value: false, onChanged: (bool newValue) {
new MaterialPageRoute(builder: (ctxt) => new SecondScreen()),

But the last line of code gives me the following error, and I don’t know how to resolve it:


The return type ‘SecondScreen’ isn’t a widget as required by the
closure’s context.

So, SecondScreen is not a stateless widget. But how can I modify the MaterialPageRouter to successfully transition to this new page.

Any help would be greatly appreciated.

Source: Android Questions