The Only Use Case For Singletons In Flutter, Your App Logger

Fred Grott
7 min readJul 8, 2021

I am going to show you the only use case for singletons in Flutter, implementing your app logger. Along the way some basic introduction to the Developer log function, the logging package, the logging appenders package, and some other OOP patterns.

Singleton Properties

Compared to multiple instances of the same thing, singletons take up less memory. But, they cannot be tested. And, generally, we seek to have close to 100 percent unit test coverage in Flutter apps; thus Singletons do not have much use not only Flutter apps but also dart scripts as well.

But, there is one use case left that fits perfectly for Singleton use; and that is your App Logger. It’s small in-memory footprint, as it’s not a big view model.

The other twist to constructing a Singleton App Logger is that back in 2016 when Flutter was first introduced, there was almost no log and logging infrastructure. So a lot of developers re-invented ways to log. Rather than get confused by that logging plugin mess; I am showing you how to use the logging package and few accessories, such as logging appenders.

The Developer Log Function

The Developer Log function only records a single event, let me show you via the Dart-SDK. The

--

--