talira

A simple, fast service locator for Dart and Flutter

open sourceMITfree

get_it is a type-safe service locator for Dart and Flutter: register services, models and business logic once at startup and get them from anywhere in the app in constant time, without a BuildContext, code generation or reflection. Objects can be registered as singletons, lazy singletons or factories, async initialisation is supported, and hierarchical scopes swap registrations for states such as login and logout; real implementations are easily replaced by mocks in tests. It works in Flutter, plain Dart, server and CLI apps, and is part of the flutter_it set of packages alongside watch_it, command_it and listen_it. MIT licensed, maintained by Thomas Burkhart.

Problems it solves

  • access my services from anywhere in a Flutter app without passing BuildContext around
  • decouple my Dart code from concrete implementations so I can swap in mocks for tests
  • register objects once at startup and get the same instance everywhere in a Flutter app

Features

  • O(1) lookups of registered objects from anywhere
  • singleton, lazy singleton and factory registration
  • async singletons and startup initialisation
  • hierarchical scopes for app states such as login and logout
  • swap implementations for mocks in tests
  • no code generation, reflection or BuildContext