addPlugin method

  1. @override
Future<void> addPlugin(
  1. DataStorePluginInterface plugin, {
  2. required AmplifyAuthProviderRepository authProviderRepo,
})
override

Adds a plugin to the category.

Implementation

@override
Future<void> addPlugin(
  DataStorePluginInterface plugin, {
  required AmplifyAuthProviderRepository authProviderRepo,
}) async {
  if (plugins.isEmpty) {
    try {
      // Extra step to configure datastore specifically.
      // Note: The native datastore plugins are not added
      // in the `onAttachedToEngine` but rather in the `configure()
      await plugin.configureDataStore(
        modelProvider: plugin.modelProvider!,
        errorHandler: plugin.errorHandler,
      );
      _plugins.add(plugin);
    } on AmplifyAlreadyConfiguredException {
      _plugins.add(plugin);
    } on Object catch (e) {
      try {
        throw AmplifyException.fromMap(
          Map<String, String>.from(
            // ignore: avoid_dynamic_calls
            (e as dynamic /* PlatformException */).details as Map,
          ),
        );
      } on NoSuchMethodError {
        // fallthrough
      }
      rethrow;
    }
  } else {
    throw PluginError(
      'DataStore plugin has already been added, multiple plugins for '
      'DataStore category are currently not supported.',
    );
  }
}