initInstances method
override
The initialization method. Subclasses override this method to hook into the platform and otherwise configure their services. Subclasses must call "super.initInstances()".
The binding is not fully initialized when this method runs (for example, other binding mixins may not yet have run their initInstances method). For this reason, code in this method should avoid invoking callbacks or synchronously triggering any code that would normally assume that the bindings are ready.
By convention, if the service is to be provided as a singleton,
it should be exposed as
link
MixinClassName.instance
, a static
getter with a non-nullable return type that returns
MixinClassName._instance
, a static field that is set by
initInstances()
. To improve the developer experience, the
return value should actually be
BindingBase.checkInstance(_instance)
(see checkInstance), as
in the example below.
mixin BazBinding on BindingBase {
@override
void initInstances() {
super.initInstances();
_instance = this;
// ...binding initialization...
}
static BazBinding get instance => BindingBase.checkInstance(_instance);
static BazBinding? _instance;
// ...binding features...
}
Implementation
@override
void initInstances() {
// This is initialized here because it's needed for the `super.initInstances`
// call. It can't be handled as a ctor initializer because it's dependent
// on `platformDispatcher`. It can't be handled in the ctor itself because
// the base class ctor is called first and calls `initInstances`.
window = TestWindow.fromPlatformDispatcher(platformDispatcher: platformDispatcher);
super.initInstances();
_instance = this;
timeDilation = 1.0; // just in case the developer has artificially changed it for development
if (overrideHttpClient) {
binding.setupHttpOverrides();
}
_testTextInput = TestTextInput(onCleared: _resetFocusedEditable);
}