registerWith static method

void registerWith(
  1. Registrar registrar
)

Implementation

static void registerWith(Registrar registrar) {
  DotLottieFlutterPlatform.instance = DotLottieFlutterWeb();

  final script =
      web.document.createElement('script') as web.HTMLScriptElement;
  script.type = 'module';
  script.text = '''
  import { DotLottie } from 'https://cdn.jsdelivr.net/npm/@lottiefiles/dotlottie-web@0.55.0/+esm';
  window.DotLottie = DotLottie;
  window.dispatchEvent(new Event('dotlottie-ready'));
''';
  web.document.head?.appendChild(script);

  ui_web.platformViewRegistry.registerViewFactory('dotlottie_view', (
    int viewId,
  ) {
    final view = DotLottieWebView(viewId, registrar);
    _viewInstances[viewId] = view;

    if (_creationParams.containsKey(viewId)) {
      Future.delayed(Duration(milliseconds: 100), () {
        final params = _creationParams.remove(viewId);
        if (params != null) {
          view.initializeFromParams(params);
        }
      });
    }

    return view.element;
  });
}