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