Flutter get_it Injectable Setup — DI the Right Way
Learn flutter get_it injectable setup: service locator basics, injectable code generation, Supabase registration, and mocking get_it for widget tests.
Passing dependencies down through ten constructors gets old fast. Your AuthRepository needs an http.Client , your AuthBloc needs the repository, your widget needs the bloc — and suddenly every constructor signature is a freight train. This is exactly the problem that flutter get_it injectable solves: get_it gives you a simple service locator, and injectable generates the boilerplate that registers everything for you. This tutorial walks you through the full setup on Flutter 3.x: registering services by hand, moving to injectable code generation, wiring up a Supabase client and repositories, and — the part most guides skip — mocking those services in widget tests. What you'll learn What get_it is and how to register services manually registerSingleton vs registerFactory vs registerLazySingleton Setting up injectable with build_runner for generated DI config Registering a Supabase client and repositories with get_it How to use get_it in Flutter with constructor injection Mocking get_it services for widget tests with GetIt.I.reset() Common mistakes that make flutter service locator not working Step 0 — Add the dependencies First, add get_it. If you want the generated setup (recommended), add injectable and build_runner too: flutter pub add get_it flutter pub add injectable flutter pub add injectable_generator build_runner --dev No version pins — let pub resolve compatible versions for your Flutter 3.x SDK. The rest of this guide uses these three packages and assumes you already know async/await and futures . Step 1 — get_it basics: register and retrieve get_it is a service locator: a global registry where you store instances and ask for them back later. The core pattern has two lines — register once, read anywhere: import 'package:get_it/get_it.dart'; final…