a7c41063fa
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.
124 lines
3.6 KiB
Dart
124 lines
3.6 KiB
Dart
import 'package:flutter/material.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);
|
|
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 style = Theme.of(context).textTheme.bodySmall?.copyWith(
|
|
color: Theme.of(context).colorScheme.onSurfaceVariant,
|
|
);
|
|
final text = DefaultTextStyle.merge(style: style, child: footer);
|
|
return Padding(
|
|
padding: const EdgeInsetsDirectional.fromSTEB(
|
|
settingsRowInset,
|
|
settingsFieldGap + 2,
|
|
settingsRowInset,
|
|
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: settingsRowInset,
|
|
vertical: 12,
|
|
),
|
|
child: child,
|
|
),
|
|
);
|
|
}
|