Member-only story

The Wrong Way To Do Flutter App Services

Fred Grott
3 min readJul 25, 2022

--

It would be nice if the Flutter Skeleton App Template taught some worthwhile Flutter coding best practices. Unfortunately, it’s not really set up that way. Let me show why the Skeleton App service implementation is wrong and how to fix it.

Settings Service In Flutter Skeleton App Template

Here is the Settings Service of the Flutter Skeleton App:

Let me show you how you should view the service layers with a set of opinionated questions:

1. Where are the non-nullable fields and methods?

2. Is it a service that should be allowed to be created with different instances?

3. Where, or how, do we dependency-inject non widget dependencies?

Obviously, the answer to the question of where are the non-nullables is that the themeMode method since it returns something is non-nullable. That means that this service, to test it, requires us to mock it or create a fake class with our own implemented method. And the second question builds on that by…

--

--

Fred Grott
Fred Grott

No responses yet