Posts

Showing posts with the label DI

What the Heck Is Dependency Injection?

  Have you ever written a widget that   somehow   ended up knowing about your database, API client, local storage, and maybe even Firebase auth? Be honest we’ve all been there. At first, everything works fine. You call a service from your UI, get the result, display it. But a few weeks later… Your widget’s  build()  method is 100+ lines Your  HomeScreen  knows about every feature in the app Writing a test requires bootstrapping your entire app Welcome to  tight coupling hell . The good news? There’s a simple fix it’s called  Dependency Injection (DI) . And in this post, I’m going to show you  why it matters ,  how it works in Flutter , and  how to start using it in your real apps . Let’s go. First, What the Heck Is Dependency Injection? Think of it like this: Instead of your class creating everything it needs, you just  give  it what it needs from the outside. For example, if a class needs an  ApiClient , you don...