merge(app): land settings layout rhythm
This commit is contained in:
@@ -8,9 +8,10 @@ export 'settings_theme.dart';
|
|||||||
|
|
||||||
/// A native text field with a label and one supporting line. Both platforms lay
|
/// 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
|
/// the label out as wrapping text above the field; Material uses an outlined
|
||||||
/// [TextField] and iOS a [CupertinoTextField]. Labels and helper/error copy are
|
/// [TextField] and iOS a [CupertinoTextField]. The label is a compact secondary
|
||||||
/// never line-capped, so large text cannot truncate them. No font sizes, heights
|
/// line (like the web field label) while the section title carries the weight.
|
||||||
/// or colours are fixed here.
|
/// 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 {
|
class SettingsTextField extends StatelessWidget {
|
||||||
const SettingsTextField({
|
const SettingsTextField({
|
||||||
super.key,
|
super.key,
|
||||||
@@ -35,13 +36,17 @@ class SettingsTextField extends StatelessWidget {
|
|||||||
final hasError = error.trim().isNotEmpty;
|
final hasError = error.trim().isNotEmpty;
|
||||||
// The label is laid out as normal wrapping text on both platforms. A
|
// The label is laid out as normal wrapping text on both platforms. A
|
||||||
// Material floating label is single-line and ellipsizes the workspace label
|
// Material floating label is single-line and ellipsizes the workspace label
|
||||||
// at narrow widths or large text, dropping required words.
|
// 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(
|
final labelWidget = ExcludeSemantics(
|
||||||
child: Text(
|
child: Text(
|
||||||
label,
|
label,
|
||||||
style: usesCupertinoControls(context)
|
style: usesCupertinoControls(context)
|
||||||
? settingsTextStyle(context)
|
? settingsTextStyle(context, secondary: true)
|
||||||
: theme.textTheme.titleSmall,
|
: theme.textTheme.labelMedium?.copyWith(
|
||||||
|
color: theme.colorScheme.onSurfaceVariant,
|
||||||
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
if (!usesCupertinoControls(context)) {
|
if (!usesCupertinoControls(context)) {
|
||||||
|
|||||||
@@ -3,25 +3,35 @@
|
|||||||
/// Everything else (control heights, font sizes, colours, button padding) comes
|
/// Everything else (control heights, font sizes, colours, button padding) comes
|
||||||
/// from the active Material or Cupertino theme, so text scaling and platform
|
/// from the active Material or Cupertino theme, so text scaling and platform
|
||||||
/// defaults are never overridden here.
|
/// defaults are never overridden here.
|
||||||
|
///
|
||||||
|
/// The rhythm follows the web Settings page: one centred column, an 8px gap
|
||||||
|
/// between a section's compact title and its grouped body, and 16px between
|
||||||
|
/// sections. The web's 12px field label and helper lines are secondary type in
|
||||||
|
/// [settingsTextStyle]/[SettingsTextField], not fixed sizes.
|
||||||
library;
|
library;
|
||||||
|
|
||||||
/// A comfortable reading width on wide windows; the body is centred inside it.
|
/// A comfortable reading width on wide windows; the body is centred inside it.
|
||||||
const double settingsContentMaxWidth = 720;
|
const double settingsContentMaxWidth = 720;
|
||||||
|
|
||||||
/// Space between the Settings sections.
|
/// Space between the Settings sections (web `.settings` grid gap).
|
||||||
const double settingsSectionGap = 24;
|
const double settingsSectionGap = 16;
|
||||||
|
|
||||||
/// Space between a section title and its controls.
|
/// Space between a compact section title and its grouped body, and between the
|
||||||
const double settingsTitleGap = 12;
|
/// blocks inside a section (web `.settings-section` grid gap).
|
||||||
|
const double settingsTitleGap = 8;
|
||||||
|
|
||||||
/// Space between a field and its supporting text.
|
/// Space between a field label and its field, and between stacked secondary
|
||||||
const double settingsFieldGap = 6;
|
/// lines (web `.settings-field` gap).
|
||||||
|
const double settingsFieldGap = 4;
|
||||||
|
|
||||||
/// Space between wrapped action buttons.
|
/// Space between wrapped action buttons.
|
||||||
const double settingsControlGap = 8;
|
const double settingsControlGap = 8;
|
||||||
|
|
||||||
/// Padding around the page body on narrow windows.
|
/// Page insets on narrow windows: a little more room above the first title,
|
||||||
const double settingsPagePadding = 16;
|
/// and a clear run-out below the last section (web `.settings` padding).
|
||||||
|
const double settingsPageTopPadding = 20;
|
||||||
|
const double settingsPageSidePadding = 16;
|
||||||
|
const double settingsPageBottomPadding = 32;
|
||||||
|
|
||||||
/// Padding inside a standard Material card / Cupertino inset row.
|
/// Padding inside a standard Material card / Cupertino inset row.
|
||||||
const double settingsCardPadding = 16;
|
const double settingsCardPadding = 16;
|
||||||
|
|||||||
@@ -116,7 +116,14 @@ class _SettingsScreenState extends State<SettingsScreen> {
|
|||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final content = SafeArea(
|
final content = SafeArea(
|
||||||
child: SingleChildScrollView(
|
child: SingleChildScrollView(
|
||||||
padding: const EdgeInsets.all(settingsPagePadding),
|
// Web `.settings` page insets: 20 above the title, 16 at the sides and
|
||||||
|
// a clear 32 below the last section.
|
||||||
|
padding: const EdgeInsetsDirectional.fromSTEB(
|
||||||
|
settingsPageSidePadding,
|
||||||
|
settingsPageTopPadding,
|
||||||
|
settingsPageSidePadding,
|
||||||
|
settingsPageBottomPadding,
|
||||||
|
),
|
||||||
child: Center(
|
child: Center(
|
||||||
child: ConstrainedBox(
|
child: ConstrainedBox(
|
||||||
constraints: const BoxConstraints(
|
constraints: const BoxConstraints(
|
||||||
@@ -125,38 +132,48 @@ class _SettingsScreenState extends State<SettingsScreen> {
|
|||||||
child: Column(
|
child: Column(
|
||||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||||
children: <Widget>[
|
children: <Widget>[
|
||||||
const _SectionTitle('Connection'),
|
_SettingsSection(
|
||||||
const SizedBox(height: settingsTitleGap),
|
title: 'Connection',
|
||||||
SettingsConnectionSection(
|
child: SettingsConnectionSection(
|
||||||
controller: _controller,
|
controller: _controller,
|
||||||
serverUrlField: _serverUrlField,
|
serverUrlField: _serverUrlField,
|
||||||
|
),
|
||||||
),
|
),
|
||||||
const SizedBox(height: settingsSectionGap),
|
const SizedBox(height: settingsSectionGap),
|
||||||
const _SectionTitle('Workspace'),
|
_SettingsSection(
|
||||||
const SizedBox(height: settingsTitleGap),
|
title: 'Workspace',
|
||||||
SettingsWorkspaceSection(
|
child: SettingsWorkspaceSection(
|
||||||
controller: _controller,
|
controller: _controller,
|
||||||
workspaceField: _workspaceField,
|
workspaceField: _workspaceField,
|
||||||
|
),
|
||||||
),
|
),
|
||||||
if (widget.notifications != null) ...<Widget>[
|
if (widget.notifications != null) ...<Widget>[
|
||||||
const SizedBox(height: settingsSectionGap),
|
const SizedBox(height: settingsSectionGap),
|
||||||
const _SectionTitle('Notifications'),
|
// The permission tile draws its own compact title row, so
|
||||||
const SizedBox(height: settingsTitleGap),
|
// Settings must not add a second "Notifications" heading.
|
||||||
SettingsNotificationsSection(
|
_SettingsSection(
|
||||||
controller: widget.notifications!,
|
child: SettingsNotificationsSection(
|
||||||
|
controller: widget.notifications!,
|
||||||
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
if (widget.onOpenSchedules != null) ...<Widget>[
|
if (widget.onOpenSchedules != null) ...<Widget>[
|
||||||
const SizedBox(height: settingsSectionGap),
|
const SizedBox(height: settingsSectionGap),
|
||||||
const _SectionTitle('Schedules'),
|
_SettingsSection(
|
||||||
const SizedBox(height: settingsTitleGap),
|
title: 'Schedules',
|
||||||
SettingsSchedulesSection(onOpen: widget.onOpenSchedules!),
|
child: SettingsSchedulesSection(
|
||||||
|
onOpen: widget.onOpenSchedules!,
|
||||||
|
),
|
||||||
|
),
|
||||||
],
|
],
|
||||||
if (widget.onOpenTemplates != null) ...<Widget>[
|
if (widget.onOpenTemplates != null) ...<Widget>[
|
||||||
const SizedBox(height: settingsSectionGap),
|
const SizedBox(height: settingsSectionGap),
|
||||||
const _SectionTitle('Templates'),
|
_SettingsSection(
|
||||||
const SizedBox(height: settingsTitleGap),
|
title: 'Templates',
|
||||||
SettingsTemplatesSection(onOpen: widget.onOpenTemplates!),
|
child: SettingsTemplatesSection(
|
||||||
|
onOpen: widget.onOpenTemplates!,
|
||||||
|
),
|
||||||
|
),
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
@@ -178,13 +195,27 @@ class _SettingsScreenState extends State<SettingsScreen> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class _SectionTitle extends StatelessWidget {
|
/// One grouped Settings section: a compact title followed by its body at the
|
||||||
const _SectionTitle(this.title);
|
/// web's 8px title gap. Sections are separated by [settingsSectionGap]. A null
|
||||||
|
/// title lets a body (the notification tile) draw its own compact heading.
|
||||||
|
class _SettingsSection extends StatelessWidget {
|
||||||
|
const _SettingsSection({required this.child, this.title});
|
||||||
|
|
||||||
final String title;
|
final String? title;
|
||||||
|
final Widget child;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Text(title, style: settingsTextStyle(context, title: true));
|
final title = this.title;
|
||||||
|
return Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||||
|
children: <Widget>[
|
||||||
|
if (title != null) ...<Widget>[
|
||||||
|
Text(title, style: settingsTextStyle(context, title: true)),
|
||||||
|
const SizedBox(height: settingsTitleGap),
|
||||||
|
],
|
||||||
|
child,
|
||||||
|
],
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,99 @@
|
|||||||
|
import 'package:flutter/cupertino.dart';
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
|
import 'package:pipelines_app/core/transport/pipelines_client.dart'
|
||||||
|
as transport;
|
||||||
|
import 'package:pipelines_app/features/attention/notify/notification_controller.dart';
|
||||||
|
import 'package:pipelines_app/features/attention/notify/notification_store.dart';
|
||||||
|
import 'package:pipelines_app/features/settings/settings_layout.dart';
|
||||||
|
import 'package:pipelines_app/features/settings/settings_screen.dart';
|
||||||
|
import 'package:pipelines_app/features/settings/settings_store.dart';
|
||||||
|
import 'package:pipelines_app/features/settings/settings_trust_warning.dart';
|
||||||
|
|
||||||
|
import 'fake_channel.dart';
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
testWidgets('sections use one centred column and the web rhythm', (
|
||||||
|
tester,
|
||||||
|
) async {
|
||||||
|
await _pump(tester);
|
||||||
|
|
||||||
|
final connection = tester.getRect(find.text('Connection'));
|
||||||
|
final serverUrlLabel = tester.getRect(find.text('Server URL'));
|
||||||
|
final warning = tester.getRect(find.byType(SettingsTrustWarning));
|
||||||
|
final workspace = tester.getRect(find.text('Workspace'));
|
||||||
|
|
||||||
|
// One column: the 720px reading width is centred in an 800px window.
|
||||||
|
expect(connection.left, closeTo(40, 0.01));
|
||||||
|
expect(connection.right, closeTo(760, 0.01));
|
||||||
|
|
||||||
|
// The compact title sits 8px above its grouped body, and sections are 16px
|
||||||
|
// apart, as on the web Settings page.
|
||||||
|
expect(
|
||||||
|
serverUrlLabel.top - connection.bottom,
|
||||||
|
closeTo(settingsTitleGap, 0.01),
|
||||||
|
);
|
||||||
|
expect(workspace.top - warning.bottom, closeTo(settingsSectionGap, 0.01));
|
||||||
|
|
||||||
|
// The field label is a compact secondary line, not a second title.
|
||||||
|
final label = tester.widget<Text>(find.text('Server URL'));
|
||||||
|
final theme = Theme.of(tester.element(find.text('Server URL')));
|
||||||
|
expect(label.style?.color, theme.colorScheme.onSurfaceVariant);
|
||||||
|
expect(label.style?.fontSize, theme.textTheme.labelMedium?.fontSize);
|
||||||
|
expect(
|
||||||
|
label.style?.fontSize,
|
||||||
|
lessThan(theme.textTheme.titleMedium!.fontSize!),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
testWidgets('the notification tile is the section\'s only title', (
|
||||||
|
tester,
|
||||||
|
) async {
|
||||||
|
final notifications = NotificationController(
|
||||||
|
store: MemoryNotificationStore(),
|
||||||
|
);
|
||||||
|
addTearDown(notifications.dispose);
|
||||||
|
await _pump(tester, notifications: notifications);
|
||||||
|
|
||||||
|
expect(find.text('Notifications'), findsOneWidget);
|
||||||
|
expect(find.text('Connection'), findsOneWidget);
|
||||||
|
});
|
||||||
|
|
||||||
|
testWidgets('Cupertino keeps the compact secondary field label', (
|
||||||
|
tester,
|
||||||
|
) async {
|
||||||
|
await _pump(tester, platform: TargetPlatform.iOS);
|
||||||
|
|
||||||
|
final label = tester.widget<Text>(find.text('Server URL'));
|
||||||
|
final context = tester.element(find.text('Server URL'));
|
||||||
|
expect(
|
||||||
|
label.style?.color,
|
||||||
|
CupertinoColors.secondaryLabel.resolveFrom(context),
|
||||||
|
);
|
||||||
|
expect(find.byType(CupertinoTextField), findsNWidgets(2));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> _pump(
|
||||||
|
WidgetTester tester, {
|
||||||
|
TargetPlatform platform = TargetPlatform.android,
|
||||||
|
NotificationController? notifications,
|
||||||
|
}) async {
|
||||||
|
await tester.binding.setSurfaceSize(const Size(800, 1600));
|
||||||
|
addTearDown(() => tester.binding.setSurfaceSize(null));
|
||||||
|
final factory = FakeChannelFactory();
|
||||||
|
final client = transport.PipelinesClient(channelFactory: factory.call);
|
||||||
|
addTearDown(client.dispose);
|
||||||
|
await tester.pumpWidget(
|
||||||
|
MaterialApp(
|
||||||
|
theme: ThemeData(platform: platform),
|
||||||
|
home: SettingsScreen(
|
||||||
|
client: client,
|
||||||
|
store: MemorySettingsStore(),
|
||||||
|
notifications: notifications,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
await tester.pump();
|
||||||
|
await tester.pump();
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user