Your next intuition could be to define each menu item only once but produce different navigation objects depending on platform. Let’s see how that looks:

Then you can use the NavigationMenu object as follows:

This looks promising:

We defined each navigation item only once and it magically works for Android and iOS.

The API is easy to use on each page.

The page still has full control of the Scaffold.

However, we quickly run into problems:

The NavigationMenu object does not have access to context so you can’t, for instance, automatically close the drawer once an item is clicked.

object does not have access to so you can’t, for instance, automatically close the drawer once an item is clicked. We end up with a ugly pattern of having to pass two parameters every time even though only one of them is set. If we forget to pass one, there’s no warning until we test on that platform and it blows up.

The currently selected page is not part of the object state.

When you start needing access to BuilderContext and the state needs to be passed into you, it should become apparent that what you need is a StatelessWidget .

In Flutter, the cleanest way to do this is to define a new widget with the API that we would like to have and build Scaffold as the output of that widget.

We can then refer to this widget from every page of the app and it will render the correct navigation on both platforms and correctly highlight the current page.

You can make this pattern more robust by having each page provide its own NavigationItem and having a registry that collects all of them in one place. That makes setting selectedItem easier as well.

This pattern fixes all of the shortcomings of the previous approach but you end up losing a bit of freedom in configuring the scaffold. In this case, that might be OK given that most use cases of scaffold rarely go outside of body , floatingActionButton and appBar .

This is just one way of writing platform specific widget code in Flutter. Hopefully the concepts introduced here will help you come up with your own patterns.