- Flutter 桌面端通过 dart:ffi 调用 Rust Core cdylib - 实现 ECDH P-256 密钥协商、HKDF 子密钥派生、AES-256-GCM 控制帧 - Android 被控端用派生密钥做控制帧加密与媒体包 MAC - 新增 libopus JNI 骨架,默认回退 MediaCodec - 新增 aosp/zhanxun/neutral 签名变体与系统 sharedUserId - 本机独立信令服务与设置页开关 - 新增 .gitignore 排除所有编译产物与打包目录
173 lines
5.6 KiB
Dart
173 lines
5.6 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('指纹 ${device.shortFingerprint} · ${device.resolution}',
|
|
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('确认手机与主控端处于同一网段', style: Theme.of(context).textTheme.bodySmall),
|
|
const SizedBox(height: 12),
|
|
OutlinedButton.icon(
|
|
onPressed: onRefresh,
|
|
icon: const Icon(Icons.refresh),
|
|
label: const Text('重新扫描'),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
}
|