Files
pipelines/app/lib/features/settings/settings_controls.dart
T
alan 3ec580c2d9 Restyle Settings as flat grouped list sections (F9) and scroll it behind the bar (F1)
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.
2026-10-31 03:07:20 +00:00

191 lines
5.9 KiB
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<String> 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: <Widget>[
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: <Widget>[
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: <Widget>[
CupertinoButton.filled(
key: primaryKey,
onPressed: onPrimary,
child: Text(primaryLabel),
),
CupertinoButton(
key: secondaryKey,
onPressed: onSecondary,
child: Text(secondaryLabel),
),
],
);
}
return Wrap(
spacing: settingsControlGap,
runSpacing: settingsControlGap,
children: <Widget>[
FilledButton(
key: primaryKey,
onPressed: onPrimary,
child: Text(primaryLabel),
),
OutlinedButton(
key: secondaryKey,
onPressed: onSecondary,
child: Text(secondaryLabel),
),
],
);
}
}