installDeferredComponent method Null safety

Future<void> installDeferredComponent(
  1. {required String componentName}
)

Requests that an assets-only deferred component identified by the componentName be downloaded and installed.

This method returns a Future that will complete when the feature is installed and any assets are ready to be used. When an error occurs, the future will complete with an error.

This method should be used for asset-only deferred components or loading just the assets from a component with both dart code and assets. Deferred components containing dart code should call loadLibrary() on a deferred imported library's prefix to ensure that the dart code is properly loaded as loadLibrary() will provide the loading unit id needed for the dart library loading process. For example:

import 'split_component.dart' deferred as SplitComponent;
...
SplitComponent.loadLibrary();

This method will not load associated dart libraries contained in the component, though it will download the files necessary and subsequent calls to loadLibrary() to load will complete faster.

Assets installed by this method may be accessed in the same way as any other local asset by providing a string path to the asset.

See also:

  • uninstallDeferredComponent, a method to request the uninstall of a component.
  • loadLibrary, the dart method to trigger the installation of the corresponding deferred component that contains the dart library.

Implementation

static Future<void> installDeferredComponent({required String componentName}) async {
  await SystemChannels.deferredComponent.invokeMethod<void>(
    'installDeferredComponent',
    <String, dynamic>{ 'loadingUnitId': -1, 'componentName': componentName },
  );
}