Member-only story

A New Google Flutter Best Practice, Shared App Data Singletons

Fred Grott
2 min readMay 31, 2022

--

I am going to show you a new way to declare a singleton in Flutter that saves some steps in that it can be used just like inherited widget objects in only having to declare it once in the widget tree. Shared App Data API is a new small API that was added to the Flutter SDK last fall, 2021.

The Shared App Data API

The Shared App Data API was added to the Flutter SDK in fall of 2021:

A Use Case

The WidgetsApp, MaterialApp, and CupertinoApp create this widget automatically. The situation we would use it in is the situation where we want to use a custom widget that is not in the Flutter SDK. Instead of requiring the end-developer to have to include a widget parameter when declaring the custom widget in the widget tree; the developer of the custom widget can assume setting of the parameter via the SharedAppData class and set it to a default value if not set or null.

In short words like you were five, custom widget developers no longer need to use a customization of…

--

--

Fred Grott
Fred Grott

No responses yet