build method
Widget
build(
- BuildContext context,
- QuillController controller,
- Embed node,
- bool readOnly,
- bool inline,
- 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,
),
);
}