119 lines
4.0 KiB
Dart
119 lines
4.0 KiB
Dart
import 'package:flutter/material.dart';
|
|
|
|
/// 串流控制卡片。
|
|
///
|
|
/// 主界面不渲染投屏画面,画面统一显示在独立原生窗口里;窗口尺寸按视频比例自动适配,
|
|
/// 关闭窗口即停止投屏,所以这里只保留「请求投屏」一个动作。
|
|
class MirrorBar extends StatelessWidget {
|
|
const MirrorBar({
|
|
super.key,
|
|
required this.connected,
|
|
required this.streaming,
|
|
required this.windowOpen,
|
|
required this.granted,
|
|
required this.busy,
|
|
required this.resolution,
|
|
required this.frames,
|
|
required this.error,
|
|
required this.onRequest,
|
|
});
|
|
|
|
final bool connected;
|
|
final bool streaming;
|
|
final bool windowOpen;
|
|
final bool granted;
|
|
final bool busy;
|
|
final String resolution;
|
|
final int frames;
|
|
final String error;
|
|
|
|
final VoidCallback onRequest;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final theme = Theme.of(context);
|
|
final statusColor = _statusColor(theme);
|
|
|
|
return Card(
|
|
margin: const EdgeInsets.fromLTRB(12, 8, 12, 4),
|
|
child: Padding(
|
|
padding: const EdgeInsets.all(14),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Row(
|
|
children: [
|
|
Icon(Icons.screen_share, size: 18, color: statusColor),
|
|
const SizedBox(width: 8),
|
|
Text('串流', style: theme.textTheme.titleMedium),
|
|
const SizedBox(width: 10),
|
|
Container(
|
|
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 2),
|
|
decoration: BoxDecoration(
|
|
color: statusColor.withValues(alpha: 0.12),
|
|
borderRadius: BorderRadius.circular(10),
|
|
),
|
|
child: Text(
|
|
_statusText(),
|
|
style: theme.textTheme.labelSmall?.copyWith(color: statusColor),
|
|
),
|
|
),
|
|
const Spacer(),
|
|
if (windowOpen)
|
|
Text('串流窗口已打开', style: theme.textTheme.labelSmall),
|
|
],
|
|
),
|
|
const SizedBox(height: 4),
|
|
Text(
|
|
_detailText(),
|
|
style: theme.textTheme.bodySmall,
|
|
maxLines: 2,
|
|
overflow: TextOverflow.ellipsis,
|
|
),
|
|
const SizedBox(height: 12),
|
|
SizedBox(
|
|
width: double.infinity,
|
|
child: FilledButton.icon(
|
|
onPressed: connected && !busy && !windowOpen ? onRequest : null,
|
|
icon: Icon(
|
|
streaming ? Icons.cast_connected : Icons.play_circle_outline,
|
|
),
|
|
label: Text(streaming ? '投屏中 · 关闭窗口即停止' : '请求投屏'),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
String _statusText() {
|
|
if (streaming) return '接收画面中';
|
|
if (error.isNotEmpty) return '异常';
|
|
if (windowOpen && granted) return '已允许,等待画面';
|
|
if (windowOpen) return '等待被控端确认';
|
|
if (connected) return '已连接,未投屏';
|
|
return '未连接';
|
|
}
|
|
|
|
Color _statusColor(ThemeData theme) {
|
|
if (streaming) return Colors.green;
|
|
if (error.isNotEmpty) return theme.colorScheme.error;
|
|
if (windowOpen) return Colors.orange;
|
|
if (connected) return theme.colorScheme.primary;
|
|
return theme.colorScheme.outline;
|
|
}
|
|
|
|
String _detailText() {
|
|
if (!connected) return '先在上方连接被控端,再请求投屏';
|
|
if (streaming) {
|
|
final size = resolution.isEmpty ? '未知分辨率' : resolution;
|
|
return '$size · 已接收 $frames 帧 · 关闭独立窗口会立即停止投屏';
|
|
}
|
|
if (error.isNotEmpty) return error;
|
|
if (windowOpen && granted) return '被控端已允许投屏,正在等待首帧';
|
|
if (windowOpen) return '已向被控端发送投屏请求,请在其弹窗中点击「允许」';
|
|
return '点击「请求投屏」会按视频比例弹出独立窗口播放画面';
|
|
}
|
|
}
|