build method

  1. @override
Widget build(
  1. BuildContext context,
  2. QuillController controller,
  3. Embed node,
  4. bool readOnly,
  5. bool inline,
  6. TextStyle textStyle,
)

Implementation

@override
Widget build(
  BuildContext context,
  QuillController controller,
  Embed node,
  bool readOnly,
  bool inline,
  TextStyle textStyle,
) {
  var videoUrl = node.value.data;
  if (isYouTubeUrl(videoUrl)) {
    final youtubeID = YoutubePlayer.convertUrlToId(videoUrl);
    if (youtubeID != null) {
      videoUrl = 'https://www.youtube.com/embed/$youtubeID';
    }
  }

  final (height, width, margin, alignment) = getWebElementAttributes(node);

  ui.PlatformViewRegistry().registerViewFactory(
    videoUrl,
    (id) => html.IFrameElement()
      ..style.width = width
      ..style.height = height
      ..src = videoUrl
      ..style.border = 'none'
      ..style.margin = margin
      ..style.alignSelf = alignment
      ..attributes['loading'] = 'lazy',
  );

  return SizedBox(
    height: 500,
    child: HtmlElementView(
      viewType: videoUrl,
    ),
  );
}