Files
pipelines/app/lib/features/settings/settings_group.dart
T
2026-12-03 23:56:39 +00:00

134 lines
4.0 KiB
Dart

import 'package:flutter/material.dart';
import '../../ui/theme/app_design_tokens.dart';
import 'settings_layout.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).
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: kept for callers, the Material
/// group does not depend on it.
final bool leadingRows;
@override
Widget build(BuildContext context) {
final title = this.title;
final footer = this.footer;
final theme = Theme.of(context);
final tokens = AppDesignTokens.of(context);
final inset = settingsRowInsetOf(context);
return Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
if (title != null)
Padding(
padding: EdgeInsetsDirectional.fromSTEB(
inset,
0,
inset,
tokens.density.space(settingsTitleGap),
),
child: Semantics(
header: true,
child: Text(title, style: settingsHeaderStyle(context)),
),
),
if (children.isNotEmpty)
Material(
type: MaterialType.card,
color: tokens.panelFill(
theme.colorScheme,
theme.colorScheme.surfaceContainer,
),
elevation: 0,
shape: RoundedRectangleBorder(
borderRadius: tokens.corners(
BorderRadius.circular(settingsGroupRadius),
),
side: tokens.frameSide ?? BorderSide.none,
),
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: inset,
color: theme.colorScheme.outlineVariant,
),
child,
],
],
),
),
if (footer != null) _footer(context, footer),
],
);
}
Widget _footer(BuildContext context, Widget footer) {
final style = Theme.of(context).textTheme.bodySmall?.copyWith(
color: Theme.of(context).colorScheme.onSurfaceVariant,
);
final text = DefaultTextStyle.merge(style: style, child: footer);
final inset = settingsRowInsetOf(context);
return Padding(
padding: EdgeInsetsDirectional.fromSTEB(
inset,
AppDesignTokens.of(context).density.space(settingsFieldGap + 2),
inset,
0,
),
child: text,
);
}
}
/// A group header's text style.
TextStyle settingsHeaderStyle(BuildContext context) {
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: settingsRowInsetOf(context),
vertical: AppDesignTokens.of(context).density.space(12),
),
child: child,
),
);
}