init method
Executed when a PatapataApp
run
s or when a this Plugin is
added to the PatapataApp
after run
.
This may return a Future for asynchronous initialization.
Always call super.init
before any other overridden code.
If any of the callbacks fail for any reason,
the App will not continue to execute callbacks
and will execute the onInitFailure
callback if given.
Otherwise, it will silently die. (Not do anything)
Implementation
@mustCallSuper
FutureOr<bool> init(App app) async {
if (_initialized) {
throw StateError('$name is already initialized.');
}
if (!dependencies.every((t) => app.hasPlugin(t))) {
throw StateError('$name does not have all dependencies satisfied.');
}
if (kIsTest) {
setMockMethodCallHandler();
setMockStreamHandler();
}
_app = app;
_initialized = true;
return true;
}