addPlugin method

  1. @override
Future<void> addPlugin()

Called when the plugin is added to the category.

Implementation

@override
Future<void> addPlugin() async {
  _channel.setMethodCallHandler(_methodCallHandler);
  try {
    _transferProgressEventChannel.receiveBroadcastStream(0).listen((event) {
      var eventData = (event as Map).cast<String, dynamic>();
      String uuid = eventData["uuid"];
      int currentBytes = eventData["currentBytes"];
      int totalBytes = eventData["totalBytes"];

      void Function(TransferProgress)? callback =
          _transferProgressionCallbackMap[uuid];

      if (callback != null) {
        callback(TransferProgress(currentBytes, totalBytes));
      }
    });

    return await _channel.invokeMethod('configureStorage',
        <String, dynamic>{'hasPrefixResolver': prefixResolver != null});
  } on PlatformException catch (e) {
    if (e.code == "AmplifyAlreadyConfiguredException") {
      throw AmplifyAlreadyConfiguredException(
          AmplifyExceptionMessages.alreadyConfiguredDefaultMessage,
          recoverySuggestion:
              AmplifyExceptionMessages.alreadyConfiguredDefaultSuggestion);
    } else {
      throw AmplifyException.fromMap(Map<String, String>.from(e.details));
    }
  }
}