Code cleanup for defaultEmbedBuilderWeb

pull/890/head
X Code 3 years ago
parent 4e1bc307bf
commit 401f317690
  1. 18
      example/lib/universal_ui/universal_ui.dart

@ -59,26 +59,26 @@ Widget defaultEmbedBuilderWeb(
), ),
); );
case BlockEmbed.videoType: case BlockEmbed.videoType:
final youtubeID = YoutubePlayer.convertUrlToId(node.value.data); var videoUrl = node.value.data;
var embedUrl = node.value.data; if (videoUrl.contains('youtube.com') || videoUrl.contains('youtu.be')) {
final youtubeID = YoutubePlayer.convertUrlToId(videoUrl);
if (youtubeID != null) { if (youtubeID != null) {
embedUrl = videoUrl = 'https://www.youtube.com/embed/$youtubeID';
'https://www.youtube.com/embed/${YoutubePlayer.convertUrlToId(embedUrl)}'; }
} }
UniversalUI().platformViewRegistry.registerViewFactory( UniversalUI().platformViewRegistry.registerViewFactory(
embedUrl, videoUrl,
(id) => html.IFrameElement() (id) => html.IFrameElement()
..width = MediaQuery.of(context).size.width.toString() ..width = MediaQuery.of(context).size.width.toString()
..height = MediaQuery.of(context).size.height.toString() ..height = MediaQuery.of(context).size.height.toString()
..src = embedUrl ..src = videoUrl
..style.border = 'none'); ..style.border = 'none');
return SizedBox( return SizedBox(
height: 500, height: 500,
child: HtmlElementView( child: HtmlElementView(
viewType: embedUrl, viewType: videoUrl,
), ),
); );
default: default:

Loading…
Cancel
Save