import 'package:flutter/material.dart'; class ControlToolbar extends StatelessWidget { const ControlToolbar({super.key, required this.enabled, required this.onEvent}); final bool enabled; final void Function(String type, Map payload) onEvent; @override Widget build(BuildContext context) { return Card( child: Padding( padding: const EdgeInsets.all(12), child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Row( children: [ const Icon(Icons.gamepad), const SizedBox(width: 8), Text('远程控制', style: Theme.of(context).textTheme.titleSmall), const Spacer(), if (!enabled) Text('连接后可用', style: Theme.of(context).textTheme.labelSmall), ], ), const SizedBox(height: 10), Wrap( spacing: 8, runSpacing: 8, children: [ _Action( icon: Icons.touch_app, label: '点击中心', enabled: enabled, onPressed: () => onEvent('touch', { 'action': 0, 'pointerId': 1, 'x': 960, 'y': 540, 'pressure': 800, }), ), _Action( icon: Icons.arrow_back, label: '返回', enabled: enabled, onPressed: () => onEvent('key', {'action': 0, 'keycode': 4, 'modifiers': 0}), ), _Action( icon: Icons.home, label: '主页', enabled: enabled, onPressed: () => onEvent('key', {'action': 0, 'keycode': 3, 'modifiers': 0}), ), _Action( icon: Icons.mouse, label: '滚轮向下', enabled: enabled, onPressed: () => onEvent('wheel', {'deltaX': 0, 'deltaY': -1, 'buttons': 0}), ), _Action( icon: Icons.content_paste, label: '发送剪贴板', enabled: enabled, onPressed: () => onEvent('clipboard', {'text': 'TTSTD Connect'}), ), _Action( icon: Icons.screen_share, label: '请求投屏', enabled: enabled, onPressed: () => onEvent('requestMirror', const {}), ), _Action( icon: Icons.stop_screen_share, label: '停止投屏', enabled: enabled, onPressed: () => onEvent('stopMirror', const {}), ), ], ), ], ), ), ); } } class _Action extends StatelessWidget { const _Action({ required this.icon, required this.label, required this.enabled, required this.onPressed, }); final IconData icon; final String label; final bool enabled; final VoidCallback onPressed; @override Widget build(BuildContext context) { return OutlinedButton.icon( onPressed: enabled ? onPressed : null, icon: Icon(icon, size: 18), label: Text(label), style: OutlinedButton.styleFrom( padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 10), ), ); } }