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.
136 lines
4.2 KiB
Dart
136 lines
4.2 KiB
Dart
import 'package:flutter/material.dart';
|
|
|
|
import 'settings_layout.dart';
|
|
|
|
export 'settings_theme.dart';
|
|
|
|
/// A native text field with a label and one supporting line. The label is laid
|
|
/// out as wrapping text above the field; Material uses an outlined
|
|
/// [TextField]. 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: theme.textTheme.labelMedium?.copyWith(
|
|
color: theme.colorScheme.onSurfaceVariant,
|
|
),
|
|
),
|
|
);
|
|
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(),
|
|
),
|
|
),
|
|
),
|
|
],
|
|
);
|
|
}
|
|
}
|
|
|
|
/// 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) {
|
|
return Wrap(
|
|
spacing: settingsControlGap,
|
|
runSpacing: settingsControlGap,
|
|
children: <Widget>[
|
|
FilledButton(
|
|
key: primaryKey,
|
|
onPressed: onPrimary,
|
|
child: Text(primaryLabel),
|
|
),
|
|
OutlinedButton(
|
|
key: secondaryKey,
|
|
onPressed: onSecondary,
|
|
child: Text(secondaryLabel),
|
|
),
|
|
],
|
|
);
|
|
}
|
|
}
|