injectCSSFileFromUrl method

Future<void> injectCSSFileFromUrl({
  1. required Uri urlFile,
  2. CSSLinkHtmlTagAttributes? cssLinkHtmlTagAttributes,
})

Injects an external CSS file into the WebView from a defined url.

cssLinkHtmlTagAttributes represents the possible CSS stylesheet <link> HTML attributes to be set.

NOTE: This method shouldn't be called in the WebView.onWebViewCreated or WebView.onLoadStart events, because, in these events, the WebView is not ready to handle it yet. Instead, you should call this method, for example, inside the WebView.onLoadStop event or in any other events where you know the page is ready "enough".

Implementation

Future<void> injectCSSFileFromUrl(
    {required Uri urlFile,
    CSSLinkHtmlTagAttributes? cssLinkHtmlTagAttributes}) async {
  assert(urlFile.toString().isNotEmpty);
  Map<String, dynamic> args = <String, dynamic>{};
  args.putIfAbsent('urlFile', () => urlFile.toString());
  args.putIfAbsent(
      'cssLinkHtmlTagAttributes', () => cssLinkHtmlTagAttributes?.toMap());
  await _channel.invokeMethod('injectCSSFileFromUrl', args);
}