installDeferredComponent static method
- required String componentName,
Requests that an assets-only deferred component identified by the componentName
be downloaded and installed.
This method returns a Future
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 split_component;
// ...
void _showSplit() {
// ...
split_component.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 },
);
}