buildYouTube function

Widget buildYouTube(
  1. BuildContext context,
  2. OpenUiNode node
)

YouTube(video, title?): an embedded video by id or URL. Where no web view runs, a thumbnail that opens the video.

Implementation

Widget buildYouTube(BuildContext context, OpenUiNode node) {
  final id = youTubeId(jsString(node.props['video'] ?? ''));
  if (id == null) return const SizedBox.shrink();
  final title = node.props.string('title');
  final label = title == null || title.isEmpty
      ? OpenUiLocalizations.of(context).youTubeVideo
      : title;
  final Widget body = host.canHostWebPages
      ? host.youTubeHost(
          id: id,
          title: label,
          referrer: node.services.embedReferrer,
        )
      : Semantics(
          button: true,
          label: OpenUiLocalizations.of(context).playVideo(label),
          excludeSemantics: true,
          child: GestureDetector(
            onTap: () => node.services.openUrl(
              Uri.parse('https://www.youtube.com/watch?v=$id'),
            ),
            child: Stack(
              fit: StackFit.expand,
              children: [
                Photo(
                  query: '',
                  src: 'https://i.ytimg.com/vi/$id/hqdefault.jpg',
                  aspectRatio: 16 / 9,
                  radius: 0,
                ),
                Center(
                  child: Container(
                    padding: const EdgeInsets.all(14),
                    decoration: const BoxDecoration(
                      color: Color(0xCC000000),
                      shape: BoxShape.circle,
                    ),
                    child: const Glyph(
                      'play',
                      size: 22,
                      color: Color(0xFFFFFFFF),
                    ),
                  ),
                ),
              ],
            ),
          ),
        );
  final theme = node.theme;
  return AspectRatio(
    aspectRatio: 16 / 9,
    child: ClipRRect(
      borderRadius: BorderRadius.circular(theme.radii.lg),
      child: ColoredBox(color: const Color(0xFF000000), child: body),
    ),
  );
}