Polish manager icons, alignment and card spacing

This commit is contained in:
tongtong committed 2026-11-16 11:42:37 +08:00
1 parent 40ff016f6b
commit e12cb76d68
3 files changed
+219 -68

No files matched your search

+157 -51
View File
@@ -67,17 +67,45 @@ class _AgentViewState extends State<AgentView> {
);
}
Widget button(String text, Future<void> Function() action, {bool? enabled}) =>
Padding(
padding: const EdgeInsets.only(right: 8, bottom: 8),
child: OutlinedButton(
onPressed: enabled == false || m.busy ? null : action,
child: Text(text),
Widget button(
String text,
Future<void> Function() action, {
bool? enabled,
IconData? icon,
bool inline = false,
}) => Padding(
padding: EdgeInsets.only(right: 8, bottom: inline ? 0 : 8),
child: icon == null
? OutlinedButton(
onPressed: enabled == false || m.busy ? null : action,
child: Text(text),
)
: OutlinedButton.icon(
onPressed: enabled == false || m.busy ? null : action,
icon: Icon(icon, size: 16),
label: Text(text),
),
);
Widget leftAligned(Widget child) =>
Align(alignment: Alignment.centerLeft, child: child);
Widget cardTitle(IconData icon, String text) => Padding(
padding: const EdgeInsets.only(bottom: 12),
child: Row(
children: [
Icon(icon, size: 18, color: const Color(0xFF305DDB)),
const SizedBox(width: 8),
Expanded(
child: Text(
text,
style: const TextStyle(fontSize: 16, fontWeight: FontWeight.w600),
),
),
);
],
),
);
Widget card(List<Widget> children) => Card(
child: Padding(
padding: const EdgeInsets.all(18),
padding: const EdgeInsets.all(16),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: children,
@@ -97,13 +125,15 @@ class _AgentViewState extends State<AgentView> {
value: m.localMode,
onChanged: m.busy ? null : (v) => m.setLocal(v ?? false),
),
const SizedBox(width: 6),
const Text('管理本机 Agent'),
const SizedBox(width: 20),
button('刷新 Agent', m.refresh),
const SizedBox(width: 16),
button('刷新 Agent', m.refresh, icon: Icons.refresh, inline: true),
Checkbox(
value: m.autoRefresh,
onChanged: (v) => setState(() => m.autoRefresh = v ?? false),
),
const SizedBox(width: 6),
const Text('自动刷新'),
],
),
@@ -111,12 +141,17 @@ class _AgentViewState extends State<AgentView> {
field('configPath', '本机配置路径', m.configPath, (v) => m.configPath = v),
Wrap(
children: [
button('启动后台 Agent', m.startLocal),
button('安装开机服务', m.installLocal),
button(
'启动后台 Agent',
m.startLocal,
icon: Icons.play_circle_outline,
),
button('安装开机服务', m.installLocal, icon: Icons.power_settings_new),
],
),
] else
Row(
crossAxisAlignment: CrossAxisAlignment.end,
children: [
Expanded(
child: field(
@@ -127,7 +162,15 @@ class _AgentViewState extends State<AgentView> {
),
),
const SizedBox(width: 12),
button('导入管理员凭据', m.importAdmin),
Padding(
padding: const EdgeInsets.only(bottom: 2),
child: button(
'导入管理员凭据',
m.importAdmin,
icon: Icons.file_upload,
inline: true,
),
),
],
),
Text(m.notice, style: const TextStyle(color: Colors.blueGrey)),
@@ -140,28 +183,52 @@ class _AgentViewState extends State<AgentView> {
child: LayoutBuilder(
builder: (context, size) {
final list = Card(
child: ListView(
children: [
for (final agent in m.agents)
ListTile(
selected: agent.id == m.selectedId,
title: Text(agent.id),
subtitle: Text(agent.description),
leading: Icon(
Icons.computer,
color: agent.online ? Colors.green : Colors.grey,
child: Padding(
padding: const EdgeInsets.all(8),
child: m.agents.isEmpty
? const Center(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Icon(
Icons.dns_outlined,
size: 40,
color: Colors.blueGrey,
),
SizedBox(height: 12),
Text(
'暂无 Agent',
style: TextStyle(color: Colors.blueGrey),
),
],
),
)
: ListView(
padding: EdgeInsets.zero,
children: [
for (final agent in m.agents)
ListTile(
selected: agent.id == m.selectedId,
title: Text(agent.id),
subtitle: Text(agent.description),
leading: Icon(
Icons.computer,
color: agent.online
? Colors.green
: Colors.grey,
),
onTap: m.busy ? null : () => m.select(agent.id),
),
],
),
onTap: m.busy ? null : () => m.select(agent.id),
),
],
),
);
final detail = ListView(
children: [
card([
Text(
cardTitle(
Icons.computer,
m.selected?.description ?? '选择 Agent / 被控电脑',
style: Theme.of(context).textTheme.titleMedium,
),
if (m.selected case final agent?)
Text(
@@ -170,44 +237,51 @@ class _AgentViewState extends State<AgentView> {
const SizedBox(height: 12),
Wrap(
children: [
button('读取配置', m.loadConfig, enabled: m.canManage),
button(
'读取配置',
m.loadConfig,
enabled: m.canManage,
icon: Icons.download,
),
button(
'开启 USB 自动注册',
() => m.setAutoUsb(true),
enabled: m.canManage,
icon: Icons.usb,
),
button(
'关闭 USB 自动注册',
() => m.setAutoUsb(false),
enabled: m.canManage,
icon: Icons.usb_off,
),
button(
'取消所选 USB 设备的忽略',
m.unignoreUsb,
enabled: m.canManage,
icon: Icons.undo,
),
button(
'重启 Agent',
m.restart,
enabled:
m.canManage && m.selected?.supervised == true,
icon: Icons.restart_alt,
),
],
),
]),
const SizedBox(height: 12),
card([
const Text(
'手机管理',
style: TextStyle(
fontSize: 18,
fontWeight: FontWeight.bold,
cardTitle(Icons.phone_android, '手机管理'),
leftAligned(
button(
'发现 ADB 设备',
m.discoverDevices,
enabled: m.canManage,
icon: Icons.search,
),
),
button(
'发现 ADB 设备',
m.discoverDevices,
enabled: m.canManage,
),
for (final row in m.discoveredDevices)
ListTile(
title: Text('${row['serial']} · ${row['state']}'),
@@ -240,6 +314,7 @@ class _AgentViewState extends State<AgentView> {
() =>
m.deviceOperation('device_enable', enabled: true),
enabled: m.canDevice,
icon: Icons.play_arrow,
),
button(
'停用',
@@ -248,11 +323,13 @@ class _AgentViewState extends State<AgentView> {
enabled: false,
),
enabled: m.canDevice,
icon: Icons.pause,
),
button(
'移除配置',
() => m.deviceOperation('device_remove'),
enabled: m.canDevice,
icon: Icons.delete_outline,
),
],
),
@@ -281,16 +358,18 @@ class _AgentViewState extends State<AgentView> {
const Text('此模式仍要求手机开启 TCP adbd。'),
],
),
button('添加手机', m.addDevice, enabled: m.canManage),
]),
card([
const Text(
'Agent 配置',
style: TextStyle(
fontSize: 18,
fontWeight: FontWeight.bold,
leftAligned(
button(
'添加手机',
m.addDevice,
enabled: m.canManage,
icon: Icons.add,
),
),
]),
const SizedBox(height: 12),
card([
cardTitle(Icons.tune, 'Agent 配置'),
const SizedBox(height: 10),
field(
'json',
@@ -299,7 +378,14 @@ class _AgentViewState extends State<AgentView> {
(v) => m.configText = v,
lines: 12,
),
button('保存并应用配置', m.saveConfig, enabled: m.canManage),
leftAligned(
button(
'保存并应用配置',
m.saveConfig,
enabled: m.canManage,
icon: Icons.save,
),
),
if (m.localMode) ...[
field(
'enroll',
@@ -307,7 +393,13 @@ class _AgentViewState extends State<AgentView> {
m.enrollmentPath,
(v) => m.enrollmentPath = v,
),
button('导入设备端凭据', m.importEnrollment),
leftAligned(
button(
'导入设备端凭据',
m.importEnrollment,
icon: Icons.file_upload,
),
),
field(
'agentToken',
'ADS_AGENT_TOKEN',
@@ -315,19 +407,33 @@ class _AgentViewState extends State<AgentView> {
(v) => m.enrollmentToken = v,
secret: true,
),
button('初始化本机配置', m.initializeLocal),
leftAligned(
button(
'初始化本机配置',
m.initializeLocal,
icon: Icons.settings,
),
),
],
]),
const SizedBox(height: 12),
card([
Wrap(
crossAxisAlignment: WrapCrossAlignment.center,
children: [
button('读取日志', m.readLogs, enabled: m.canManage),
button(
'读取日志',
m.readLogs,
enabled: m.canManage,
icon: Icons.receipt_long,
inline: true,
),
Checkbox(
value: m.followLogs,
onChanged: (v) =>
setState(() => m.followLogs = v ?? false),
),
const SizedBox(width: 6),
const Text('持续跟随日志'),
],
),
+24 -4
View File
@@ -81,11 +81,15 @@ class ActionButton extends m.StatelessWidget {
padding: const m.EdgeInsets.symmetric(horizontal: 14, vertical: 9),
minimumSize: const m.Size(0, 36),
color: primary ? c.CupertinoColors.activeBlue : null,
// 填充按钮的背景是主色,未指定前景色时图标会沿用主色而在蓝底上不可见。
foregroundColor: primary && onPressed != null
? c.CupertinoColors.white
: null,
onPressed: onPressed,
child: m.DefaultTextStyle.merge(
style: m.TextStyle(
fontSize: 13,
color: primary ? c.CupertinoColors.white : null,
color: primary && onPressed != null ? c.CupertinoColors.white : null,
),
child: content,
),
@@ -193,8 +197,18 @@ class TextField extends m.StatelessWidget {
minLines: minLines,
style: style,
placeholder: decoration.hintText,
prefix: decoration.prefixIcon,
suffix: decoration.suffixIcon,
prefix: decoration.prefixIcon == null
? null
: m.Padding(
padding: const m.EdgeInsets.only(left: 10),
child: decoration.prefixIcon!,
),
suffix: decoration.suffixIcon == null
? null
: m.Padding(
padding: const m.EdgeInsets.only(right: 8),
child: decoration.suffixIcon!,
),
padding: const m.EdgeInsets.all(12),
),
],
@@ -238,7 +252,13 @@ class SwitchListTile extends m.StatelessWidget {
children: [title, ?subtitle],
),
),
c.CupertinoSwitch(value: value, onChanged: onChanged),
m.SizedBox(
width: 40,
child: m.FittedBox(
fit: m.BoxFit.contain,
child: c.CupertinoSwitch(value: value, onChanged: onChanged),
),
),
],
),
),
+38 -13
View File
@@ -76,7 +76,13 @@ class _ManagerViewState extends State<ManagerView> {
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10),
),
leading: Icon(icon, color: Colors.blueGrey, size: 21),
leading: Icon(
icon,
color: page == i
? const Color(0xFF305DDB)
: Colors.blueGrey,
size: 21,
),
title: Text(
title,
style: const TextStyle(
@@ -115,6 +121,19 @@ class _ManagerViewState extends State<ManagerView> {
),
),
),
Container(
width: 1,
decoration: const BoxDecoration(
color: Color(0xFFD5DCE8),
boxShadow: [
BoxShadow(
color: Color(0x1A000000),
blurRadius: 6,
offset: Offset(1, 0),
),
],
),
),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
@@ -300,7 +319,7 @@ class _ManagerViewState extends State<ManagerView> {
),
),
const SizedBox(width: 16),
OutlinedButton(
OutlinedButton.icon(
onPressed: m.repository.sessions.isEmpty
? null
: () => m.action(() async {
@@ -308,7 +327,8 @@ class _ManagerViewState extends State<ManagerView> {
await m.disconnect(id);
}
}),
child: const Text('断开全部'),
icon: const Icon(Icons.link_off, size: 16),
label: const Text('断开全部'),
),
],
),
@@ -422,9 +442,10 @@ class _ManagerViewState extends State<ManagerView> {
),
const SizedBox(width: 12),
if (s == null)
FilledButton(
FilledButton.icon(
onPressed: pending || d.busy ? null : () => m.connect(d),
child: const Text('连接设备'),
icon: const Icon(Icons.add_link, size: 16),
label: const Text('连接设备'),
)
else
Wrap(
@@ -453,9 +474,10 @@ class _ManagerViewState extends State<ManagerView> {
: '独立窗口投屏',
),
),
OutlinedButton(
OutlinedButton.icon(
onPressed: pending ? null : () => m.disconnect(d.id),
child: const Text('断开'),
icon: const Icon(Icons.link_off, size: 16),
label: const Text('断开'),
),
],
),
@@ -523,7 +545,7 @@ class _ManagerViewState extends State<ManagerView> {
icon: const Icon(Icons.refresh),
label: const Text('读取设备列表'),
),
OutlinedButton(
OutlinedButton.icon(
onPressed: () => m.action(() async {
final result = await m.repository.run(m.repository.settings.adb, [
'start-server',
@@ -531,7 +553,8 @@ class _ManagerViewState extends State<ManagerView> {
m.log(result.isEmpty ? 'ADB Server 已启动' : result);
await m.localAdb();
}),
child: const Text('启动 ADB Server'),
icon: const Icon(Icons.play_arrow, size: 16),
label: const Text('启动 ADB Server'),
),
],
),
@@ -569,14 +592,16 @@ class _ManagerViewState extends State<ManagerView> {
),
),
const Spacer(),
TextButton(
TextButton.icon(
onPressed: m.openLogDirectory,
child: const Text('打开日志文件夹'),
icon: const Icon(Icons.folder_open, size: 16),
label: const Text('打开日志文件夹'),
),
TextButton(
TextButton.icon(
onPressed: () =>
Clipboard.setData(ClipboardData(text: m.logs.join('\n'))),
child: const Text('复制日志'),
icon: const Icon(Icons.copy, size: 16),
label: const Text('复制日志'),
),
],
),