import 'package:flutter/material.dart'; class VideoView extends StatelessWidget { const VideoView({ super.key, this.textureId, this.connected = false, this.resolution = '', this.pts, this.error = '', this.standalone = false, this.aspectRatio = 16 / 9, }); final int? textureId; final bool connected; final String resolution; final int? pts; /// 原生解码链路的失败原因,为空表示没有错误。 final String error; /// 画面已弹出到独立窗口:主界面不再渲染纹理,只显示提示。 final bool standalone; /// 按实际码流宽高算出的比例(竖屏投屏时不再是 16:9)。 final double aspectRatio; @override Widget build(BuildContext context) { final theme = Theme.of(context); return AspectRatio( aspectRatio: aspectRatio > 0 ? aspectRatio : 16 / 9, child: ClipRRect( borderRadius: BorderRadius.circular(16), child: DecoratedBox( decoration: BoxDecoration( gradient: LinearGradient( colors: [ theme.colorScheme.surfaceContainerHighest, theme.colorScheme.surfaceContainerLowest, ], begin: Alignment.topLeft, end: Alignment.bottomRight, ), ), child: Stack( fit: StackFit.expand, children: [ if (standalone) Column( mainAxisAlignment: MainAxisAlignment.center, children: [ Icon(Icons.open_in_new, size: 72, color: theme.colorScheme.primary.withValues(alpha: 0.6)), const SizedBox(height: 12), Text('画面已在独立窗口播放', style: theme.textTheme.titleMedium), const SizedBox(height: 4), Text('把它拖到任意显示器,双击可全屏;关闭独立窗口后画面回到这里', style: theme.textTheme.bodySmall, textAlign: TextAlign.center), ], ) else if (textureId != null) Texture(textureId: textureId!) else Column( mainAxisAlignment: MainAxisAlignment.center, children: [ Icon(Icons.connected_tv, size: 72, color: theme.colorScheme.primary.withValues(alpha: 0.6)), const SizedBox(height: 12), Text(connected ? '视频通道已建立' : '等待投屏画面', style: theme.textTheme.titleMedium), const SizedBox(height: 4), Text( error.isNotEmpty ? error : 'H.264/H.265 → External Texture', style: theme.textTheme.bodySmall?.copyWith( color: error.isNotEmpty ? theme.colorScheme.error : theme.textTheme.bodySmall?.color, ), textAlign: TextAlign.center, ), ], ), if (resolution.isNotEmpty) Positioned( top: 12, left: 12, child: _Badge( icon: Icons.videocam, label: resolution, color: connected ? theme.colorScheme.primary : theme.colorScheme.outline, ), ), if (pts != null) Positioned( top: 12, right: 12, child: _Badge(icon: Icons.timer, label: 'PTS $pts', color: theme.colorScheme.outline), ), ], ), ), ), ); } } class _Badge extends StatelessWidget { const _Badge({required this.icon, required this.label, required this.color}); final IconData icon; final String label; final Color color; @override Widget build(BuildContext context) { return Container( padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 6), decoration: BoxDecoration( color: Colors.black54, borderRadius: BorderRadius.circular(20), ), child: Row( mainAxisSize: MainAxisSize.min, children: [ Icon(icon, size: 14, color: color), const SizedBox(width: 6), Text(label, style: const TextStyle(color: Colors.white, fontSize: 12)), ], ), ); } }