feat(app): register native Settings on the shared live session

This commit is contained in:
2026-10-21 18:55:50 +01:00
parent 7b327f012b
commit d05aa0cfbc
15 changed files with 278 additions and 54 deletions
@@ -2,12 +2,9 @@ import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'settings_layout.dart';
import 'settings_theme.dart';
/// Whether the current platform expects Cupertino controls. The app's theme is
/// the single source of the platform answer, so dark mode and platform overrides
/// stay consistent with the rest of the shell.
bool usesCupertinoControls(BuildContext context) =>
Theme.of(context).platform == TargetPlatform.iOS;
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
@@ -40,7 +37,12 @@ class SettingsTextField extends StatelessWidget {
// Material floating label is single-line and ellipsizes the workspace label
// at narrow widths or large text, dropping required words.
final labelWidget = ExcludeSemantics(
child: Text(label, style: theme.textTheme.titleSmall),
child: Text(
label,
style: usesCupertinoControls(context)
? settingsTextStyle(context)
: theme.textTheme.titleSmall,
),
);
if (!usesCupertinoControls(context)) {
return Column(
@@ -85,9 +87,6 @@ class SettingsTextField extends StatelessWidget {
],
);
}
final supportingColor = hasError
? theme.colorScheme.error
: theme.colorScheme.onSurfaceVariant;
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
@@ -109,7 +108,11 @@ class SettingsTextField extends StatelessWidget {
const SizedBox(height: settingsFieldGap),
Text(
hasError ? error : helper,
style: theme.textTheme.bodySmall?.copyWith(color: supportingColor),
style: settingsTextStyle(
context,
error: hasError,
secondary: !hasError,
),
),
],
);
@@ -26,6 +26,7 @@ class SettingsScreen extends StatefulWidget {
this.initialEndpoint,
this.store,
this.ping,
this.embedded = false,
});
final transport.PipelinesClient client;
@@ -40,6 +41,9 @@ class SettingsScreen extends StatefulWidget {
/// Test seam for the exact ping request. Production uses `client.call('ping')`.
final PingCallback? ping;
/// The application shell already owns the native navigation bar and safe area.
final bool embedded;
@override
State<SettingsScreen> createState() => _SettingsScreenState();
}
@@ -123,6 +127,7 @@ class _SettingsScreenState extends State<SettingsScreen> {
),
),
);
if (widget.embedded) return content;
if (usesCupertinoControls(context)) {
return CupertinoPageScaffold(
navigationBar: const CupertinoNavigationBar(middle: Text('Settings')),
@@ -143,6 +148,6 @@ class _SectionTitle extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Text(title, style: Theme.of(context).textTheme.titleMedium);
return Text(title, style: settingsTextStyle(context, title: true));
}
}
@@ -26,7 +26,6 @@ class SettingsConnectionSection extends StatelessWidget {
@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
return Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
@@ -64,18 +63,14 @@ class SettingsConnectionSection extends StatelessWidget {
const SizedBox(height: settingsFieldGap),
Text(
controller.endpointSaveError,
style: theme.textTheme.bodySmall?.copyWith(
color: theme.colorScheme.error,
),
style: settingsTextStyle(context, error: true),
),
],
if (controller.actionError.isNotEmpty) ...<Widget>[
const SizedBox(height: settingsFieldGap),
Text(
controller.actionError,
style: theme.textTheme.bodySmall?.copyWith(
color: theme.colorScheme.error,
),
style: settingsTextStyle(context, error: true),
),
],
const SizedBox(height: settingsTitleGap),
@@ -102,13 +97,19 @@ class SettingsStatusCard extends StatelessWidget {
final title = lines.isEmpty ? '' : lines.first;
final details = lines.length > 1 ? lines.sublist(1) : const <String>[];
final titleColor = switch (state.kind) {
transport.ConnectionKind.connected => theme.colorScheme.primary,
transport.ConnectionKind.disconnected => theme.colorScheme.error,
_ => theme.colorScheme.onSurface,
transport.ConnectionKind.connected =>
usesCupertinoControls(context)
? CupertinoTheme.of(context).primaryColor
: theme.colorScheme.primary,
transport.ConnectionKind.disconnected => settingsErrorColor(context),
_ => settingsTextStyle(context).color,
};
final titleWidget = Text(
title,
style: theme.textTheme.titleMedium?.copyWith(color: titleColor),
style: settingsTextStyle(
context,
title: true,
).copyWith(color: titleColor),
);
return SettingsCard(
child: Column(
@@ -129,12 +130,7 @@ class SettingsStatusCard extends StatelessWidget {
titleWidget,
for (final line in details) ...<Widget>[
const SizedBox(height: settingsFieldGap),
Text(
line,
style: theme.textTheme.bodyMedium?.copyWith(
color: theme.colorScheme.onSurfaceVariant,
),
),
Text(line, style: settingsTextStyle(context, secondary: true)),
],
],
),
@@ -156,7 +152,6 @@ class SettingsWorkspaceSection extends StatelessWidget {
@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
final saveError = controller.workspaceSaveError;
final canSave = canSaveWorkspace(controller.workspaceDraft);
return Column(
@@ -193,16 +188,11 @@ class SettingsWorkspaceSection extends StatelessWidget {
const SizedBox(height: settingsFieldGap),
Text(
savedWorkspaceLine(controller.savedWorkspace),
style: theme.textTheme.bodyMedium,
style: settingsTextStyle(context),
),
if (saveError.isNotEmpty) ...<Widget>[
const SizedBox(height: settingsFieldGap),
Text(
saveError,
style: theme.textTheme.bodySmall?.copyWith(
color: theme.colorScheme.error,
),
),
Text(saveError, style: settingsTextStyle(context, error: true)),
],
],
);
@@ -0,0 +1,42 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import '../../ui/adaptive/host.dart';
bool usesCupertinoControls(BuildContext context) =>
usesCupertinoHost(context) ||
Theme.of(context).platform == TargetPlatform.iOS;
Color settingsErrorColor(BuildContext context) => usesCupertinoControls(context)
? CupertinoColors.destructiveRed.resolveFrom(context)
: Theme.of(context).colorScheme.error;
/// Resolve native text roles from the actual host, not Material's fallback
/// light theme when mounted under a dark CupertinoApp.
TextStyle settingsTextStyle(
BuildContext context, {
bool title = false,
bool secondary = false,
bool error = false,
}) {
if (usesCupertinoControls(context)) {
final text = CupertinoTheme.of(context).textTheme;
return (title ? text.navTitleTextStyle : text.textStyle).copyWith(
color: error
? settingsErrorColor(context)
: (secondary ? CupertinoColors.secondaryLabel : CupertinoColors.label)
.resolveFrom(context),
);
}
final theme = Theme.of(context);
final base = (title
? theme.textTheme.titleMedium
: theme.textTheme.bodyMedium)!;
return base.copyWith(
color: error
? theme.colorScheme.error
: secondary
? theme.colorScheme.onSurfaceVariant
: base.color,
);
}
@@ -12,7 +12,6 @@ class SettingsTrustWarning extends StatelessWidget {
@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
final icon = usesCupertinoControls(context)
? CupertinoIcons.exclamationmark_triangle
: Icons.warning_amber_rounded;
@@ -20,7 +19,7 @@ class SettingsTrustWarning extends StatelessWidget {
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Icon(icon, color: theme.colorScheme.error),
Icon(icon, color: settingsErrorColor(context)),
const SizedBox(width: settingsControlGap),
Expanded(
child: Column(
@@ -28,16 +27,12 @@ class SettingsTrustWarning extends StatelessWidget {
children: <Widget>[
Text(
trustTitle,
style: theme.textTheme.titleSmall?.copyWith(
color: theme.colorScheme.error,
),
style: settingsTextStyle(context, title: true, error: true),
),
const SizedBox(height: settingsFieldGap),
Text(
trustBody,
style: theme.textTheme.bodyMedium?.copyWith(
color: theme.colorScheme.onSurfaceVariant,
),
style: settingsTextStyle(context, secondary: true),
),
],
),