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 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: [ 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: [ for (final (index, child) in children.indexed) ...[ 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, ), ); }