3ec580c2d9
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.
152 lines
4.9 KiB
Dart
152 lines
4.9 KiB
Dart
import 'package:flutter/cupertino.dart';
|
|
import 'package:flutter/material.dart';
|
|
|
|
import '../../ui/theme/app_theme.dart';
|
|
import 'settings_layout.dart';
|
|
import 'settings_theme.dart';
|
|
|
|
/// One grouped Settings section: a short header, a flat rounded group of rows
|
|
/// and an optional one-line footer.
|
|
///
|
|
/// Material draws the header in the theme's primary `titleSmall` and the rows
|
|
/// on a flat `surfaceContainer` with hairline dividers (no elevation).
|
|
/// Cupertino uses the stock inset-grouped [CupertinoListSection], whose rows
|
|
/// sit on `secondarySystemGroupedBackground` over the page's
|
|
/// `systemGroupedBackground`.
|
|
class SettingsGroup extends StatelessWidget {
|
|
const SettingsGroup({
|
|
super.key,
|
|
required this.children,
|
|
this.title,
|
|
this.footer,
|
|
this.leadingRows = false,
|
|
});
|
|
|
|
final String? title;
|
|
final List<Widget> children;
|
|
|
|
/// A short line (or two) under the group: helper copy, a warning.
|
|
final Widget? footer;
|
|
|
|
/// Whether the rows carry leading icons: Cupertino then starts its
|
|
/// dividers at the titles (the stock inset), otherwise at the row text.
|
|
final bool leadingRows;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final title = this.title;
|
|
final footer = this.footer;
|
|
if (usesCupertinoControls(context)) {
|
|
return CupertinoListSection.insetGrouped(
|
|
margin: EdgeInsets.zero,
|
|
backgroundColor: AppColors.groupedBackground,
|
|
header: title == null
|
|
? null
|
|
: Text(title, style: settingsHeaderStyle(context)),
|
|
footer: footer == null ? null : _footer(context, footer),
|
|
additionalDividerMargin: leadingRows ? null : 6,
|
|
children: children.isEmpty ? null : children,
|
|
);
|
|
}
|
|
final theme = Theme.of(context);
|
|
return Column(
|
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
|
children: <Widget>[
|
|
if (title != null)
|
|
Padding(
|
|
padding: const EdgeInsetsDirectional.fromSTEB(
|
|
settingsRowInset,
|
|
0,
|
|
settingsRowInset,
|
|
settingsTitleGap,
|
|
),
|
|
child: Semantics(
|
|
header: true,
|
|
child: Text(title, style: settingsHeaderStyle(context)),
|
|
),
|
|
),
|
|
if (children.isNotEmpty)
|
|
Material(
|
|
type: MaterialType.card,
|
|
color: theme.colorScheme.surfaceContainer,
|
|
elevation: 0,
|
|
shape: RoundedRectangleBorder(
|
|
borderRadius: BorderRadius.circular(settingsGroupRadius),
|
|
),
|
|
clipBehavior: Clip.antiAlias,
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
|
children: <Widget>[
|
|
for (final (index, child) in children.indexed) ...<Widget>[
|
|
if (index > 0)
|
|
Divider(
|
|
height: 1,
|
|
thickness: 1,
|
|
indent: settingsRowInset,
|
|
color: theme.colorScheme.outlineVariant,
|
|
),
|
|
child,
|
|
],
|
|
],
|
|
),
|
|
),
|
|
if (footer != null) _footer(context, footer),
|
|
],
|
|
);
|
|
}
|
|
|
|
Widget _footer(BuildContext context, Widget footer) {
|
|
final cupertino = usesCupertinoControls(context);
|
|
// Cupertino: the footnote size the stock plain list section uses for
|
|
// its own header and footer.
|
|
final style = cupertino
|
|
? settingsTextStyle(context, secondary: true).copyWith(fontSize: 13)
|
|
: Theme.of(context).textTheme.bodySmall?.copyWith(
|
|
color: Theme.of(context).colorScheme.onSurfaceVariant,
|
|
);
|
|
final text = DefaultTextStyle.merge(style: style, child: footer);
|
|
// The Cupertino section pads its own footer.
|
|
if (cupertino) return text;
|
|
return Padding(
|
|
padding: const EdgeInsetsDirectional.fromSTEB(
|
|
settingsRowInset,
|
|
settingsFieldGap + 2,
|
|
settingsRowInset,
|
|
0,
|
|
),
|
|
child: text,
|
|
);
|
|
}
|
|
}
|
|
|
|
/// A group header's text style.
|
|
TextStyle settingsHeaderStyle(BuildContext context) {
|
|
if (usesCupertinoControls(context)) {
|
|
return settingsTextStyle(context).copyWith(fontWeight: FontWeight.w600);
|
|
}
|
|
final theme = Theme.of(context);
|
|
return (theme.textTheme.titleSmall ?? const TextStyle()).copyWith(
|
|
color: theme.colorScheme.primary,
|
|
);
|
|
}
|
|
|
|
/// Free-form content inside a group (a text field, a status block), padded
|
|
/// like a row so its edges line up with the rows' text.
|
|
class SettingsGroupItem extends StatelessWidget {
|
|
const SettingsGroupItem({super.key, required this.child});
|
|
|
|
final Widget child;
|
|
|
|
@override
|
|
Widget build(BuildContext context) => SizedBox(
|
|
width: double.infinity,
|
|
child: Padding(
|
|
padding: EdgeInsetsDirectional.symmetric(
|
|
horizontal: usesCupertinoControls(context) ? 20 : settingsRowInset,
|
|
vertical: 12,
|
|
),
|
|
child: child,
|
|
),
|
|
);
|
|
}
|