- Rust: 新增 discovery::beacon(UDP 41003),被动接收 offer、用包源地址作设备 IP、单播回 host;FFI 增加 ttstd_discovery_start/devices/connect/stop(ABI 3) - Android: 新增 HostBeacon 广播自身并解析 host 应答;ReceiverSession 在 host 为空时等信标再拨号;主界面移除 IP/信令输入框,改为显示发现状态 - Flutter: discover 优先取同网段信标结果并与信令合并去重;connect 先起监听再通知设备拨号;设备卡片标注「UDP 自动发现」 - 视频诊断: 缺少 SPS/PPS 的提示改为收到关键帧后才告警,避免刚接入就误报 - 文档: DEMO 增加发现流程、防火墙与模拟器 NAT 说明及实测截图
184 lines
6.0 KiB
Dart
184 lines
6.0 KiB
Dart
import 'package:flutter/material.dart';
|
|
|
|
import '../../core/models.dart';
|
|
|
|
class DeviceList extends StatelessWidget {
|
|
const DeviceList({
|
|
super.key,
|
|
required this.devices,
|
|
required this.selectedId,
|
|
required this.onSelected,
|
|
required this.onRefresh,
|
|
this.refreshing = false,
|
|
this.shrinkWrap = false,
|
|
});
|
|
|
|
final List<DeviceInfo> devices;
|
|
final String? selectedId;
|
|
final ValueChanged<DeviceInfo> onSelected;
|
|
final VoidCallback onRefresh;
|
|
final bool refreshing;
|
|
final bool shrinkWrap;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final theme = Theme.of(context);
|
|
return Column(
|
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
|
children: [
|
|
Padding(
|
|
padding: const EdgeInsets.fromLTRB(16, 16, 16, 8),
|
|
child: Row(
|
|
children: [
|
|
Icon(Icons.devices_other, size: 20, color: theme.colorScheme.primary),
|
|
const SizedBox(width: 8),
|
|
Text('可连接设备', style: theme.textTheme.titleMedium),
|
|
const Spacer(),
|
|
Text('${devices.length} 台', style: theme.textTheme.bodySmall),
|
|
IconButton(
|
|
tooltip: '重新发现',
|
|
onPressed: onRefresh,
|
|
icon: refreshing
|
|
? const SizedBox(
|
|
width: 16,
|
|
height: 16,
|
|
child: CircularProgressIndicator(strokeWidth: 2),
|
|
)
|
|
: const Icon(Icons.refresh),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
if (shrinkWrap)
|
|
_buildList()
|
|
else
|
|
Expanded(child: _buildList()),
|
|
],
|
|
);
|
|
}
|
|
|
|
Widget _buildList() {
|
|
if (devices.isEmpty) return _EmptyState(onRefresh: onRefresh);
|
|
return ListView.separated(
|
|
shrinkWrap: shrinkWrap,
|
|
physics: shrinkWrap ? const NeverScrollableScrollPhysics() : null,
|
|
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 8),
|
|
itemCount: devices.length,
|
|
separatorBuilder: (_, __) => const SizedBox(height: 8),
|
|
itemBuilder: (context, index) => _DeviceCard(
|
|
device: devices[index],
|
|
selected: devices[index].id == selectedId,
|
|
onTap: () => onSelected(devices[index]),
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
class _DeviceCard extends StatelessWidget {
|
|
const _DeviceCard({required this.device, required this.selected, required this.onTap});
|
|
|
|
final DeviceInfo device;
|
|
final bool selected;
|
|
final VoidCallback onTap;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final theme = Theme.of(context);
|
|
return Card(
|
|
clipBehavior: Clip.antiAlias,
|
|
color: selected ? theme.colorScheme.primaryContainer : null,
|
|
child: InkWell(
|
|
onTap: onTap,
|
|
child: Padding(
|
|
padding: const EdgeInsets.all(12),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Row(
|
|
children: [
|
|
CircleAvatar(
|
|
backgroundColor: selected ? theme.colorScheme.primary : theme.colorScheme.surfaceContainerHighest,
|
|
foregroundColor: selected ? theme.colorScheme.onPrimary : theme.colorScheme.onSurface,
|
|
child: const Icon(Icons.android),
|
|
),
|
|
const SizedBox(width: 12),
|
|
Expanded(
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Text(device.name, style: theme.textTheme.titleSmall),
|
|
const SizedBox(height: 2),
|
|
Text('${device.ip}:${device.controlPort} · ${device.model}',
|
|
style: theme.textTheme.bodySmall,
|
|
maxLines: 1,
|
|
overflow: TextOverflow.ellipsis),
|
|
],
|
|
),
|
|
),
|
|
if (selected) Icon(Icons.check_circle, color: theme.colorScheme.primary),
|
|
],
|
|
),
|
|
const SizedBox(height: 10),
|
|
Wrap(
|
|
spacing: 6,
|
|
runSpacing: 4,
|
|
children: [
|
|
for (final capability in device.capabilities.take(4))
|
|
Chip(
|
|
visualDensity: VisualDensity.compact,
|
|
label: Text(capability, style: theme.textTheme.labelSmall),
|
|
padding: EdgeInsets.zero,
|
|
materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
|
|
),
|
|
],
|
|
),
|
|
const SizedBox(height: 6),
|
|
Text(
|
|
[
|
|
if (device.fingerprint.isNotEmpty) '指纹 ${device.shortFingerprint}',
|
|
if (device.resolution.isNotEmpty) device.resolution,
|
|
'UDP 自动发现',
|
|
].join(' · '),
|
|
style: theme.textTheme.labelSmall?.copyWith(color: theme.colorScheme.outline),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
class _EmptyState extends StatelessWidget {
|
|
const _EmptyState({required this.onRefresh});
|
|
|
|
final VoidCallback onRefresh;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Center(
|
|
child: Column(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
const Icon(Icons.wifi_find, size: 48),
|
|
const SizedBox(height: 12),
|
|
const Text('未发现设备'),
|
|
const SizedBox(height: 4),
|
|
Text(
|
|
'被控端开启投屏后会自动出现(UDP 41003 自动发现,无需填写 IP)\n'
|
|
'若长时间未出现,请确认两端在同一网段且防火墙放行 UDP 41003',
|
|
style: Theme.of(context).textTheme.bodySmall,
|
|
textAlign: TextAlign.center,
|
|
),
|
|
const SizedBox(height: 12),
|
|
OutlinedButton.icon(
|
|
onPressed: onRefresh,
|
|
icon: const Icon(Icons.refresh),
|
|
label: const Text('重新扫描'),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
}
|