Flutter Navigation: Getting Started | raywenderlich.com

Learn about routes, navigation, and transitions for apps written using the Flutter cross-platform framework from Google.

This is a companion discussion topic for the original entry at https://www.raywenderlich.com/4562634-flutter-navigation-getting-started

In the “Popping the Stack” section, if one has a StatefulWidget one could add setState code to the the IconButton onPressed to reset variables and such. This works great, but is there a way to do this with the “<” (back) button?

        icon: Icon(Icons.arrow_back, color: Colors.green, size: 48.0),
        onPressed: () {

@filbabic Can you please help with this when you get a chance? Thank you - much appreciated! :]

1 Like

Hello Stephanie! :]

I’m not that well versed in Flutter internals, but if you’re talking about the general back button on Android or iOS, you could always override the default navigation, by adding your own leading element for the back button.

Other than that, you could pass in the ‘onWillPop’ callback, which notifies you when a widget is about to be popped. In that case, you could reset the state before popping, and then return ‘true’, to allow the Widget to be popped!

Hope this answers your question!


Thanks @filbabic. I came up with a solution which works, but not sure if it is the best solution. I’ll take a look at the onWilllPop callback as it might be better than what I did. I’m still learning.

Great tutorial! It looks like there is support for divideTiles now which looks like a good way to add separators instead of adding new rows for separators: divideTiles method - ListTile class - material library - Dart API

This tutorial is more than six months old so questions are no longer supported at the moment for it. Thank you!