Files
alan a7c41063fa Remove Cupertino branches from Settings
Keep the Material-only settings implementation and its focused tests while preserving public cupertino parameters for later cleanup. This removes unreachable platform-specific widgets and test variants without changing the Material path.
2026-11-11 05:05:57 +00:00

122 lines
4.0 KiB
Dart

import 'package:flutter/material.dart';
import '../../core/servers/machine_access.dart';
import '../../core/servers/server_catalog.dart';
import 'settings_row.dart';
import 'settings_theme.dart';
/// What a saved server's menu can do.
enum SavedServerAction { use, edit, remove, signIn }
/// The key of a saved server's actions menu button.
ValueKey<String> savedServerMenuKey(String id) =>
ValueKey<String>('settings.server.$id.menu');
/// One saved machine: a selection mark, the name, its live state (connected,
/// sign-in required, unreachable), "Pipelines and runs server" on the primary
/// and each address as a subtitle line. The trailing menu offers Sign in when
/// the machine wants its own password, plus Use, Edit and Remove.
class SavedServerRow extends StatelessWidget {
const SavedServerRow({
super.key,
required this.server,
required this.selected,
required this.busy,
required this.onAction,
this.status,
this.allowSelection = true,
this.primaryContext = false,
});
final bool allowSelection, primaryContext;
final SavedServer server;
final bool selected;
final bool busy;
final MachineAccessResult? status;
final ValueChanged<SavedServerAction> onAction;
String _label(SavedServerAction action) => switch (action) {
SavedServerAction.use =>
primaryContext
? 'Use ${server.name} for pipelines and runs'
: 'Use ${server.name}',
SavedServerAction.edit => 'Edit ${server.name}',
SavedServerAction.remove => 'Remove ${server.name}',
SavedServerAction.signIn => 'Sign in to ${server.name}',
};
List<SavedServerAction> get _actions => <SavedServerAction>[
if (status?.needsPassword ?? false) SavedServerAction.signIn,
if (allowSelection && !selected) SavedServerAction.use,
SavedServerAction.edit,
SavedServerAction.remove,
];
/// The state line: a tap on it signs in when that is what is missing.
String? get _stateText => switch (status?.access) {
null => null,
MachineAccess.connected => 'Connected',
MachineAccess.needsPassword => 'Sign in required',
MachineAccess.unreachable =>
status?.detail == null || status!.detail!.isEmpty
? 'Unreachable'
: 'Unreachable: ${status!.detail}',
};
@override
Widget build(BuildContext context) {
final Widget menu = PopupMenuButton<SavedServerAction>(
key: savedServerMenuKey(server.id),
enabled: !busy,
tooltip: '${server.name} actions',
onSelected: onAction,
itemBuilder: (context) => <PopupMenuEntry<SavedServerAction>>[
for (final action in _actions)
PopupMenuItem(value: action, child: Text(_label(action))),
],
);
final Widget mark = !allowSelection
? Icon(Icons.computer)
: selected
? Icon(
Icons.check_circle,
semanticLabel: 'Selected',
color: Theme.of(context).colorScheme.primary,
)
: Icon(Icons.radio_button_unchecked);
final needsPassword = status?.needsPassword ?? false;
final state = _stateText;
return SettingsRow(
leading: mark,
title: Text(server.name),
subtitle: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
if (state != null)
Text(
state,
key: Key('settings.server.${server.id}.state'),
style: status?.access == MachineAccess.unreachable
? TextStyle(color: settingsErrorColor(context))
: null,
),
if (selected)
Text(
primaryContext ? 'Pipelines and runs server' : 'Selected server',
),
for (final (index, address) in server.endpoints.indexed)
Text('${index == 0 ? 'Address' : 'Backup address'}: $address'),
],
),
trailing: menu,
onTap: busy
? null
: needsPassword
? () => onAction(SavedServerAction.signIn)
: !allowSelection || selected
? null
: () => onAction(SavedServerAction.use),
);
}
}