addPlugin method
Builds plugin into this app if it has not already been added.
Implementation
@override
AppBuilder addPlugin(Plugin plugin) {
_assertOpen();
final type = plugin.runtimeType;
final existing = _addedPlugins[type];
if (existing != null) {
// Allow only the same instance twice.
if (identical(existing, plugin)) return this;
throw StateError(
'A $type has already been added. Adding a second, different instance '
'would be silently ignored along with its configuration; add each '
'plugin exactly once.',
);
}
for (final dependency in plugin.dependencies) {
if (!_addedPlugins.containsKey(dependency)) {
throw StateError(
'Plugin $type requires $dependency, which has not been added. '
'Add $dependency before $type.',
);
}
}
_addedPlugins[type] = plugin;
plugin.build(this);
return this;
}