import '../../ui/theme/app_theme.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'settings_layout.dart'; import 'settings_theme.dart'; export 'settings_theme.dart'; /// A native text field with a label and one supporting line. Both platforms lay /// the label out as wrapping text above the field; Material uses an outlined /// [TextField] and iOS a [CupertinoTextField]. The label is a compact secondary /// line (like the web field label) while the section title carries the weight. /// Labels and helper/error copy are never line-capped, so large text cannot /// truncate them. No font sizes, heights or colours are fixed here. class SettingsTextField extends StatelessWidget { const SettingsTextField({ super.key, required this.controller, required this.label, required this.placeholder, required this.helper, required this.onChanged, this.error = '', this.maxLines = 1, }); final TextEditingController controller; final String label; final String placeholder; final String helper; final ValueChanged onChanged; final String error; final int maxLines; @override Widget build(BuildContext context) { final theme = Theme.of(context); final hasError = error.trim().isNotEmpty; // The label is laid out as normal wrapping text on both platforms. A // Material floating label is single-line and ellipsizes the workspace label // at narrow widths or large text, dropping required words. It is a compact // secondary line, matching the web field label, so the section title is the // one emphasised line in the group. final labelWidget = ExcludeSemantics( child: Text( label, style: usesCupertinoControls(context) ? settingsTextStyle(context, secondary: true) : theme.textTheme.labelMedium?.copyWith( color: theme.colorScheme.onSurfaceVariant, ), ), ); if (!usesCupertinoControls(context)) { return Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ labelWidget, const SizedBox(height: settingsFieldGap), Semantics( label: label, child: TextField( controller: controller, onChanged: onChanged, keyboardType: TextInputType.url, minLines: 1, maxLines: maxLines, autocorrect: false, enableSuggestions: false, textInputAction: TextInputAction.done, decoration: InputDecoration( hintText: placeholder, // `helperText`/`errorText` single-line-ellipsize unless capped // by `helperMaxLines`/`errorMaxLines`. Widgets wrap with no line // cap, so the full instructions stay readable at 2x. helper: hasError ? null : Text( helper, style: theme.textTheme.bodySmall?.copyWith( color: theme.colorScheme.onSurfaceVariant, ), ), error: hasError ? Text( error, style: theme.textTheme.bodySmall?.copyWith( color: theme.colorScheme.error, ), ) : null, border: const OutlineInputBorder(), ), ), ), ], ); } return Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ labelWidget, const SizedBox(height: settingsFieldGap), Semantics( label: label, child: CupertinoTextField( controller: controller, onChanged: onChanged, placeholder: placeholder, keyboardType: TextInputType.url, minLines: 1, maxLines: maxLines, autocorrect: false, enableSuggestions: false, clearButtonMode: OverlayVisibilityMode.editing, textInputAction: TextInputAction.done, ), ), const SizedBox(height: settingsFieldGap), Text( hasError ? error : helper, style: settingsTextStyle( context, error: hasError, secondary: !hasError, ), ), ], ); } } /// The filled primary and outlined secondary settings actions. Buttons wrap on /// a narrow window (or with large text) instead of overflowing. class SettingsActions extends StatelessWidget { const SettingsActions({ super.key, required this.primaryLabel, required this.secondaryLabel, required this.onPrimary, required this.onSecondary, this.primaryKey, this.secondaryKey, }); final String primaryLabel; final String secondaryLabel; final VoidCallback onPrimary; final VoidCallback onSecondary; final Key? primaryKey; final Key? secondaryKey; @override Widget build(BuildContext context) { if (usesCupertinoControls(context)) { return Wrap( spacing: settingsControlGap, runSpacing: settingsControlGap, children: [ CupertinoButton.filled( key: primaryKey, onPressed: onPrimary, child: Text(primaryLabel), ), CupertinoButton( key: secondaryKey, onPressed: onSecondary, child: Text(secondaryLabel), ), ], ); } return Wrap( spacing: settingsControlGap, runSpacing: settingsControlGap, children: [ FilledButton( key: primaryKey, onPressed: onPrimary, child: Text(primaryLabel), ), OutlinedButton( key: secondaryKey, onPressed: onSecondary, child: Text(secondaryLabel), ), ], ); } } /// One standard settings card: a Material [Card] or an inset-grouped Cupertino /// section, both using theme surfaces and native corner/padding defaults. class SettingsCard extends StatelessWidget { const SettingsCard({super.key, required this.child}); final Widget child; @override Widget build(BuildContext context) { if (usesCupertinoControls(context)) { return CupertinoListSection.insetGrouped( backgroundColor: AppColors.groupedBackground, margin: EdgeInsets.zero, children: [ SizedBox( width: double.infinity, child: Padding( padding: const EdgeInsets.all(settingsCardPadding), child: child, ), ), ], ); } return Card( margin: EdgeInsets.zero, child: Padding( padding: const EdgeInsets.all(settingsCardPadding), child: child, ), ); } }