Do Flutter apps dream of platform aware widgets?
Agnostic layout with platform specific widgets
Flutter is a new cross-platform app development framework which promises absolute freedom in creating user experiences regardless of the host platform. It achieves that by taking over the rendering pipeline and managing everything by itself, from laying out the components, to drawing them. Customising everything is the lifeblood of Flutter. Applications which use a heavy design branding language are an obvious target for this platform independence. Think of Netflix, it feels and looks the same regardless if it runs on your iPhone, Android or PlayStation.
But what about brands who would like to keep a platform-specific look and feel? Many companies embrace Material Design or iOS Human Interface language to keep their customer base in a familiar environment.
Flutter is equipped with packages which contain a healthy set of native widgets for iOS and Android called Cupertino and Material.

The framework is agnostic in its essence when it comes to UI. However, some widgets require an ancestor which belongs to the same “platform-specific” library, e.g. RaisedButton belongs to the Material package library and it requires a Material widget to be one of its ancestors. This presents developers with a problem in terms of reusability of the layout code.
One of the questions I get a lot from the business is — “but can we effectively build native-looking apps and still have reusable code?”
This is a valid question if we are looking for that native look and feel. My reaction to a question like that would be — yes, we can build two “native” layout trees, one for each host platform. Simple enough, right?
Well, not really. We are fooling ourselves into two implementations, exactly the opposite of what we aimed to achieve. Both trees are inherently different as both platforms have different needs in terms of dependencies and initialisation. Our holy grail of reusable code fades away.
I would like to propose an approach which allows building abstract UI and adjusts its look and behaviour depending on which platform it runs on.
Consider the following constructors for two widgets which provide a top app bar:




