Restyle Settings as flat grouped list sections (F9) and scroll it behind the bar (F1)
Servers become rows with a selection mark, addresses as subtitles and a Use/Edit/Remove menu plus an Add server row; the connection is a status row with address and Reconnect/Disconnect rows; Templates and Schedules are chevron rows in a Library group. Material groups are flat surfaceContainer surfaces with primary titleSmall headers (no Cards); Cupertino uses inset-grouped sections on the grouped background, switches for the ntfy choices. The trust warning is a footer, helper copy is shortened, Save workspace is a legible tonal/plain button, and the column starts at the bar's inset (max 720) instead of being centred. The page pads by the top media padding instead of a top SafeArea.
This commit is contained in:
@@ -0,0 +1,121 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.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 }
|
||||
|
||||
/// The key of a saved server's actions menu button.
|
||||
ValueKey<String> savedServerMenuKey(String id) =>
|
||||
ValueKey<String>('settings.server.$id.menu');
|
||||
|
||||
/// One saved server: a selection mark, the name, "Selected server" on the
|
||||
/// active one and each address (preferred, then backups) as subtitle lines.
|
||||
/// Tapping another server uses it; the trailing menu offers Use, Edit and
|
||||
/// Remove.
|
||||
class SavedServerRow extends StatelessWidget {
|
||||
const SavedServerRow({
|
||||
super.key,
|
||||
required this.server,
|
||||
required this.selected,
|
||||
required this.busy,
|
||||
required this.onAction,
|
||||
});
|
||||
|
||||
final SavedServer server;
|
||||
final bool selected;
|
||||
final bool busy;
|
||||
final ValueChanged<SavedServerAction> onAction;
|
||||
|
||||
String _label(SavedServerAction action) => switch (action) {
|
||||
SavedServerAction.use => 'Use ${server.name}',
|
||||
SavedServerAction.edit => 'Edit ${server.name}',
|
||||
SavedServerAction.remove => 'Remove ${server.name}',
|
||||
};
|
||||
|
||||
List<SavedServerAction> get _actions => <SavedServerAction>[
|
||||
if (!selected) SavedServerAction.use,
|
||||
SavedServerAction.edit,
|
||||
SavedServerAction.remove,
|
||||
];
|
||||
|
||||
Future<void> _cupertinoMenu(BuildContext context) async {
|
||||
final action = await showCupertinoModalPopup<SavedServerAction>(
|
||||
context: context,
|
||||
builder: (context) => CupertinoActionSheet(
|
||||
title: Text(server.name),
|
||||
actions: <Widget>[
|
||||
for (final action in _actions)
|
||||
CupertinoActionSheetAction(
|
||||
isDestructiveAction: action == SavedServerAction.remove,
|
||||
onPressed: () => Navigator.pop(context, action),
|
||||
child: Text(_label(action)),
|
||||
),
|
||||
],
|
||||
cancelButton: CupertinoActionSheetAction(
|
||||
onPressed: () => Navigator.pop(context),
|
||||
child: const Text('Cancel'),
|
||||
),
|
||||
),
|
||||
);
|
||||
if (action != null) onAction(action);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final cupertino = usesCupertinoControls(context);
|
||||
final Widget menu = cupertino
|
||||
? CupertinoButton(
|
||||
key: savedServerMenuKey(server.id),
|
||||
padding: EdgeInsets.zero,
|
||||
onPressed: busy ? null : () => _cupertinoMenu(context),
|
||||
child: Icon(
|
||||
CupertinoIcons.ellipsis_circle,
|
||||
semanticLabel: '${server.name} actions',
|
||||
),
|
||||
)
|
||||
: 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 = selected
|
||||
? Icon(
|
||||
cupertino
|
||||
? CupertinoIcons.checkmark_circle_fill
|
||||
: Icons.check_circle,
|
||||
semanticLabel: 'Selected',
|
||||
color: cupertino
|
||||
? CupertinoTheme.of(context).primaryColor
|
||||
: Theme.of(context).colorScheme.primary,
|
||||
)
|
||||
: Icon(
|
||||
cupertino ? CupertinoIcons.circle : Icons.radio_button_unchecked,
|
||||
color: cupertino
|
||||
? CupertinoColors.tertiaryLabel.resolveFrom(context)
|
||||
: null,
|
||||
);
|
||||
return SettingsRow(
|
||||
leading: mark,
|
||||
title: Text(server.name),
|
||||
subtitle: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: <Widget>[
|
||||
if (selected) const Text('Selected server'),
|
||||
for (final (index, address) in server.endpoints.indexed)
|
||||
Text('${index == 0 ? 'Preferred' : 'Backup $index'}: $address'),
|
||||
],
|
||||
),
|
||||
trailing: menu,
|
||||
onTap: selected || busy ? null : () => onAction(SavedServerAction.use),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user