Files
TTSTDConnect/flutter_sender/lib/features/session/mirror_bar.dart
T
tongtong d3ff293877 feat(sender): 首页移除投屏画面,请求投屏直开独立窗口,新增文件传输
- 删除首页 VideoView:画面只在独立原生窗口显示,首页改为状态卡片(分辨率/帧数/错误)

- 新增 MirrorBar 卡片,请求投屏/停止投屏从控制工具栏独立出来;点请求即打开独立窗口再下发 msg_type=8

- 停止投屏同时下发 stop 并关闭窗口;控制工具栏移除投屏按钮

- 独立窗口无画面时居中提示「等待被控端画面…」

- 新增 core/file_client.dart 与 file_browser_page:浏览/下载到 Downloads/TTSTD/上传,带进度与错误提示

- AppSettings 增加 filePort/fileToken 并接入设置页与首页文件卡片
2026-11-27 09:59:55 +08:00

133 lines
4.3 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.busy,
required this.resolution,
required this.frames,
required this.error,
required this.onRequest,
required this.onStop,
required this.onToggleWindow,
});
final bool connected;
final bool streaming;
final bool windowOpen;
final bool busy;
final String resolution;
final int frames;
final String error;
final VoidCallback onRequest;
final VoidCallback onStop;
final VoidCallback onToggleWindow;
@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
final status = _statusText();
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(
status,
style: theme.textTheme.labelSmall?.copyWith(color: statusColor),
),
),
const Spacer(),
if (windowOpen)
IconButton(
tooltip: '显示/隐藏串流窗口',
onPressed: onToggleWindow,
icon: const Icon(Icons.picture_in_picture_alt),
),
],
),
const SizedBox(height: 4),
Text(
_detailText(),
style: theme.textTheme.bodySmall,
maxLines: 2,
overflow: TextOverflow.ellipsis,
),
const SizedBox(height: 12),
Row(
children: [
Expanded(
child: FilledButton.icon(
onPressed: connected && !busy ? onRequest : null,
icon: const Icon(Icons.play_circle_outline),
label: const Text('请求投屏'),
),
),
const SizedBox(width: 10),
Expanded(
child: OutlinedButton.icon(
onPressed: onStop,
icon: const Icon(Icons.stop_circle_outlined),
label: const Text('停止投屏'),
),
),
],
),
],
),
),
);
}
String _statusText() {
if (error.isNotEmpty) return '异常';
if (streaming) return '接收画面中';
if (windowOpen) return '等待被控端确认';
if (connected) return '已连接,未投屏';
return '未连接';
}
Color _statusColor(ThemeData theme) {
if (error.isNotEmpty) return theme.colorScheme.error;
if (streaming) return Colors.green;
if (windowOpen) return Colors.orange;
if (connected) return theme.colorScheme.primary;
return theme.colorScheme.outline;
}
String _detailText() {
if (error.isNotEmpty) return error;
if (!connected) return '先在上方连接被控端,再请求投屏';
if (streaming) {
final size = resolution.isEmpty ? '未知分辨率' : resolution;
return '$size · 已接收 $frames 帧 · 画面在独立窗口显示';
}
if (windowOpen) return '已向被控端发送投屏请求,请在其弹窗中点击「允许」';
return '点击「请求投屏」后会弹出独立窗口播放画面';
}
}