GetIt class

Very simple and easy to use service locator You register your object creation or an instance of an object with registerFactory, registerSingleton or registerLazySingleton And retrieve the desired object using get or call your locator das as function as its a callable class

Constructors

GetIt.asNewInstance()
You should prefer to use the instance() method to access an instance of GetIt.
factory

Properties

allowReassignment bool
By default it's not allowed to register a type a second time. If you really need to you can disable the asserts by settingallowReassignment= true
read / write
hashCode int
The hash code for this object. [...]
read-only, inherited
ready Stream<void>
read-only
readyFuture Future<void>
read-only
runtimeType Type
A representation of the runtime type of the object.
read-only, inherited

Methods

call<T>([String instanceName]) → T
get<T>([String instanceName]) → T
retrieves or creates an instance of a registered type T depending on the registration function used for this type or based on a name.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a non-existent method or property is accessed. [...]
inherited
registerFactory<T>(FactoryFunc<T> func, {String instanceName}) → void
registers a type so that a new instance will be created on each call of get on that type T type to register func factory function for this type instanceName if you provide a value here your factory gets registered with that name instead of a type. This should only be necessary if you need to register more than one instance of one type. Its highly not recommended
registerLazySingleton<T>(FactoryFunc<T> func, {String instanceName, bool signalsReady = false}) → void
registers a type as Singleton by passing a factory function that will be called on the first call of get on that type T type to register func factory function for this type If signalsReady is set to true it means that the ready property cannot emit a ready event until this registration was signalled ready instanceName if you provide a value here your factory gets registered with that name instead of a type. This should only be necessary if you need to register more than one instance of one type. Its highly not recommended
registerSingleton<T>(T instance, {String instanceName, bool signalsReady = false}) → void
registers a type as Singleton by passing an instance of that type that will be returned on each call of get on that type T type to register If signalsReady is set to true it means that the ready property cannot emit a ready event until this registration was signalled ready instanceName if you provide a value here your instance gets registered with that name instead of a type. This should only be necessary if you need to register more than one instance of one type. Its highly not recommended
reset() → void
Clears all registered types. Handy when writing unit tests
resetLazySingleton<T>({Object instance, String instanceName, void disposingFunction(T)}) → void
Clears the instance of a lazy singleton registered type, being able to call the factory function on the first call of get on that type.
signalReady([Object instance]) → void
toString() String
A string representation of this object. [...]
inherited
unregister<T>({Object instance, String instanceName, void disposingFunction(T)}) → void
Unregister an instance of an object or a factory/singleton by Type T or by name instanceName if you need to dispose any resources you can do it using disposingFunction function that provides a instance of your class to be disposed

Operators

operator ==(Object other) bool
The equality operator. [...]
inherited

Static Properties

I GetIt
read-only
instance GetIt
read-only