Remove Cupertino branches from Settings

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.
This commit is contained in:
2026-11-11 05:05:57 +00:00
parent a2e6f8557e
commit a7c41063fa
26 changed files with 622 additions and 1353 deletions
@@ -1,6 +1,5 @@
import 'dart:async';
import 'package:flutter/cupertino.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
@@ -9,7 +8,6 @@ import 'settings_controller.dart';
import 'settings_group.dart';
import 'settings_row.dart';
import 'settings_sections.dart';
import 'settings_theme.dart';
/// The short line under the managed connection's rows.
const String managedConnectionHelp =
@@ -33,7 +31,6 @@ class ManagedConnectionSection extends StatelessWidget {
@override
Widget build(BuildContext context) {
final cupertino = usesCupertinoControls(context);
return SettingsGroup(
title: 'Connection',
leadingRows: true,
@@ -52,24 +49,20 @@ class ManagedConnectionSection extends StatelessWidget {
children: <Widget>[
SettingsStatusRow(controller: controller),
SettingsRow(
leading: Icon(cupertino ? CupertinoIcons.link : Icons.link),
leading: Icon(Icons.link),
title: const Text('Current address'),
subtitle: SelectableText('${client.endpoint ?? 'Not connected'}'),
),
SettingsRow(
action: true,
enabled: client.endpoints.isNotEmpty,
leading: Icon(
cupertino ? CupertinoIcons.arrow_clockwise : Icons.refresh,
),
leading: Icon(Icons.refresh),
title: const Text('Reconnect'),
onTap: () => unawaited(client.connectAny(client.endpoints)),
),
SettingsRow(
action: true,
leading: Icon(
cupertino ? CupertinoIcons.stop_circle : Icons.link_off,
),
leading: Icon(Icons.link_off),
title: const Text('Disconnect'),
onTap: () => unawaited(client.disconnect()),
),
@@ -1,4 +1,3 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import '../../ui/motion/quick_switch_animation.dart';
import '../chat/workspace/chat_workspace.dart';
@@ -51,7 +50,6 @@ class _QuickSwitchPreviewState extends State<QuickSwitchPreview> {
@override
Widget build(BuildContext context) {
final reduced = MediaQuery.disableAnimationsOf(context);
final cupertino = usesCupertinoControls(context);
return Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
@@ -60,16 +58,11 @@ class _QuickSwitchPreviewState extends State<QuickSwitchPreview> {
crossAxisAlignment: WrapCrossAlignment.center,
children: [
Text('Preview', style: settingsTextStyle(context, title: true)),
cupertino
? CupertinoButton(
onPressed: reduced ? null : _replay,
child: const Text('Replay animation'),
)
: TextButton.icon(
onPressed: reduced ? null : _replay,
icon: const Icon(Icons.replay),
label: const Text('Replay animation'),
),
TextButton.icon(
onPressed: reduced ? null : _replay,
icon: const Icon(Icons.replay),
label: const Text('Replay animation'),
),
],
),
Center(
@@ -120,16 +113,10 @@ class _PreviewChat extends StatelessWidget {
@override
Widget build(BuildContext context) {
final cupertino = usesCupertinoControls(context);
final color = cupertino
? (alternate ? CupertinoColors.systemTeal : CupertinoColors.systemBlue)
.resolveFrom(context)
: (alternate
? Theme.of(context).colorScheme.tertiary
: Theme.of(context).colorScheme.primary);
final background = cupertino
? CupertinoColors.secondarySystemGroupedBackground.resolveFrom(context)
: Theme.of(context).colorScheme.surfaceContainerHigh;
final color = alternate
? Theme.of(context).colorScheme.tertiary
: Theme.of(context).colorScheme.primary;
final background = Theme.of(context).colorScheme.surfaceContainerHigh;
return DecoratedBox(
decoration: BoxDecoration(
color: background,
@@ -1,9 +1,7 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import '../../core/servers/machine_access.dart';
import '../../core/servers/server_catalog.dart';
import '../../ui/adaptive/host.dart';
import '../../ui/adaptive/segmented_bar.dart';
import '../onboarding/discovery/discovered_server.dart';
import '../onboarding/discovery/discovery_panel.dart';
@@ -28,9 +26,7 @@ Future<SavedServer?> editSavedServer(
discovery: discovery ?? platformServerDiscovery(),
);
return Navigator.of(context).push<SavedServer>(
usesCupertinoHost(context)
? CupertinoPageRoute(builder: (_) => page)
: MaterialPageRoute(builder: (_) => page),
MaterialPageRoute(builder: (_) => page),
);
}
@@ -125,27 +121,6 @@ class _ServerEditorState extends State<_ServerEditor> {
required String key,
bool multiline = false,
}) {
if (usesCupertinoHost(context)) {
return Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Text(label),
const SizedBox(height: 8),
CupertinoTextField(
key: Key(key),
controller: controller,
enabled: !_saving,
placeholder: multiline ? 'wss://server.example/connect' : 'Home',
minLines: multiline ? 3 : 1,
maxLines: multiline ? null : 1,
keyboardType: multiline
? TextInputType.multiline
: TextInputType.text,
autocorrect: !multiline,
),
],
);
}
return TextField(
key: Key(key),
controller: controller,
@@ -163,18 +138,12 @@ class _ServerEditorState extends State<_ServerEditor> {
@override
Widget build(BuildContext context) {
final cupertino = usesCupertinoHost(context);
final title = widget.server == null ? 'Add server' : 'Edit server';
final saveLabel = _saving ? 'Saving server…' : 'Save server';
final save = cupertino
? CupertinoButton.filled(
onPressed: _saving ? null : _save,
child: Text(saveLabel),
)
: FilledButton(
onPressed: _saving ? null : _save,
child: Text(saveLabel),
);
final save = FilledButton(
onPressed: _saving ? null : _save,
child: Text(saveLabel),
);
final saved = _saved;
if (saved != null && widget.authenticator != null) {
final step = SafeArea(
@@ -189,7 +158,7 @@ class _ServerEditorState extends State<_ServerEditor> {
],
),
);
return _scaffold(cupertino, 'Sign in to ${saved.name}', step);
return _scaffold('Sign in to ${saved.name}', step);
}
final body = SafeArea(
child: ListView(
@@ -232,9 +201,7 @@ class _ServerEditorState extends State<_ServerEditor> {
child: Text(
_error!,
style: TextStyle(
color: cupertino
? CupertinoColors.systemRed.resolveFrom(context)
: Theme.of(context).colorScheme.error,
color: Theme.of(context).colorScheme.error,
),
),
),
@@ -244,17 +211,12 @@ class _ServerEditorState extends State<_ServerEditor> {
],
),
);
return PopScope(canPop: !_saving, child: _scaffold(cupertino, title, body));
return PopScope(canPop: !_saving, child: _scaffold(title, body));
}
Widget _scaffold(bool cupertino, String title, Widget body) => cupertino
? CupertinoPageScaffold(
navigationBar: SegmentedBar(cupertino: true, title: title),
child: body,
)
: Scaffold(
extendBodyBehindAppBar: true,
appBar: SegmentedBar(cupertino: false, title: title),
body: body,
);
Widget _scaffold(String title, Widget body) => Scaffold(
extendBodyBehindAppBar: true,
appBar: SegmentedBar(cupertino: false, title: title),
body: body,
);
}
+14 -57
View File
@@ -1,4 +1,3 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import '../../core/servers/machine_access.dart';
@@ -64,69 +63,27 @@ class SavedServerRow extends StatelessWidget {
: 'Unreachable: ${status!.detail}',
};
Future<void> _cupertinoMenu(BuildContext context) async {
final action = await showCupertinoModalPopup<SavedServerAction>(
context: context,
builder: (context) => CupertinoActionSheet(
title: Text(server.name),
actions: <Widget>[
for (final action in _actions)
CupertinoActionSheetAction(
isDestructiveAction: action == SavedServerAction.remove,
onPressed: () => Navigator.pop(context, action),
child: Text(_label(action)),
),
],
cancelButton: CupertinoActionSheetAction(
onPressed: () => Navigator.pop(context),
child: const Text('Cancel'),
),
),
);
if (action != null) onAction(action);
}
@override
Widget build(BuildContext context) {
final cupertino = usesCupertinoControls(context);
final Widget menu = cupertino
? CupertinoButton(
key: savedServerMenuKey(server.id),
padding: EdgeInsets.zero,
onPressed: busy ? null : () => _cupertinoMenu(context),
child: Icon(
CupertinoIcons.ellipsis_circle,
semanticLabel: '${server.name} actions',
),
)
: PopupMenuButton<SavedServerAction>(
key: savedServerMenuKey(server.id),
enabled: !busy,
tooltip: '${server.name} actions',
onSelected: onAction,
itemBuilder: (context) => <PopupMenuEntry<SavedServerAction>>[
for (final action in _actions)
PopupMenuItem(value: action, child: Text(_label(action))),
],
);
final Widget menu = PopupMenuButton<SavedServerAction>(
key: savedServerMenuKey(server.id),
enabled: !busy,
tooltip: '${server.name} actions',
onSelected: onAction,
itemBuilder: (context) => <PopupMenuEntry<SavedServerAction>>[
for (final action in _actions)
PopupMenuItem(value: action, child: Text(_label(action))),
],
);
final Widget mark = !allowSelection
? Icon(cupertino ? CupertinoIcons.desktopcomputer : Icons.computer)
? Icon(Icons.computer)
: selected
? Icon(
cupertino
? CupertinoIcons.checkmark_circle_fill
: Icons.check_circle,
Icons.check_circle,
semanticLabel: 'Selected',
color: cupertino
? CupertinoTheme.of(context).primaryColor
: Theme.of(context).colorScheme.primary,
color: Theme.of(context).colorScheme.primary,
)
: Icon(
cupertino ? CupertinoIcons.circle : Icons.radio_button_unchecked,
color: cupertino
? CupertinoColors.tertiaryLabel.resolveFrom(context)
: null,
);
: Icon(Icons.radio_button_unchecked);
final needsPassword = status?.needsPassword ?? false;
final state = _stateText;
return SettingsRow(
@@ -1,9 +1,7 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import '../../core/servers/machine_access.dart';
import '../../core/servers/server_catalog.dart';
import '../../ui/adaptive/host.dart';
/// What the editor does once a machine is saved: ask it whether this device
/// may use it, then either sign in with its own password or explain why it
@@ -92,21 +90,16 @@ class _SavedServerSignInStepState extends State<SavedServerSignInStep> {
@override
Widget build(BuildContext context) {
final cupertino = usesCupertinoHost(context);
final name = widget.server.name;
final errorColor = cupertino
? CupertinoColors.systemRed.resolveFrom(context)
: Theme.of(context).colorScheme.error;
final errorColor = Theme.of(context).colorScheme.error;
final result = _result;
if (result == null) {
return Row(
children: [
cupertino
? const CupertinoActivityIndicator()
: const SizedBox.square(
dimension: 16,
child: CircularProgressIndicator(strokeWidth: 2),
),
const SizedBox.square(
dimension: 16,
child: CircularProgressIndicator(strokeWidth: 2),
),
const SizedBox(width: 12),
Expanded(
child: Text('Saved. Checking whether $name needs a sign-in…'),
@@ -114,51 +107,29 @@ class _SavedServerSignInStepState extends State<SavedServerSignInStep> {
],
);
}
final later = cupertino
? CupertinoButton(
key: const Key('server-sign-in-later'),
onPressed: _busy ? null : widget.onDone,
child: const Text('Later'),
)
: TextButton(
key: const Key('server-sign-in-later'),
onPressed: _busy ? null : widget.onDone,
child: const Text('Later'),
);
final later = TextButton(
key: const Key('server-sign-in-later'),
onPressed: _busy ? null : widget.onDone,
child: const Text('Later'),
);
if (result.needsPassword) {
final field = cupertino
? CupertinoTextField(
key: const Key('server-profile-password'),
controller: _password,
obscureText: true,
autofocus: true,
enabled: !_busy,
placeholder: 'Password',
onSubmitted: (_) => _signIn(),
)
: TextField(
key: const Key('server-profile-password'),
controller: _password,
obscureText: true,
autofocus: true,
enabled: !_busy,
decoration: const InputDecoration(
labelText: 'Password',
border: OutlineInputBorder(),
),
onSubmitted: (_) => _signIn(),
);
final signIn = cupertino
? CupertinoButton.filled(
key: const Key('server-profile-sign-in'),
onPressed: _busy ? null : _signIn,
child: Text(_busy ? 'Signing in…' : 'Sign in'),
)
: FilledButton(
key: const Key('server-profile-sign-in'),
onPressed: _busy ? null : _signIn,
child: Text(_busy ? 'Signing in…' : 'Sign in'),
);
final field = TextField(
key: const Key('server-profile-password'),
controller: _password,
obscureText: true,
autofocus: true,
enabled: !_busy,
decoration: const InputDecoration(
labelText: 'Password',
border: OutlineInputBorder(),
),
onSubmitted: (_) => _signIn(),
);
final signIn = FilledButton(
key: const Key('server-profile-sign-in'),
onPressed: _busy ? null : _signIn,
child: Text(_busy ? 'Signing in…' : 'Sign in'),
);
return Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
@@ -182,17 +153,11 @@ class _SavedServerSignInStepState extends State<SavedServerSignInStep> {
],
);
}
final retry = cupertino
? CupertinoButton.filled(
key: const Key('server-profile-retry'),
onPressed: _busy ? null : _probe,
child: const Text('Try again'),
)
: FilledButton(
key: const Key('server-profile-retry'),
onPressed: _busy ? null : _probe,
child: const Text('Try again'),
);
final retry = FilledButton(
key: const Key('server-profile-retry'),
onPressed: _busy ? null : _probe,
child: const Text('Try again'),
);
return Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
@@ -1,12 +1,10 @@
import 'dart:async';
import 'package:flutter/cupertino.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import '../../core/servers/chat/machine_sign_in_dialog.dart';
import '../../core/servers/server_catalog.dart';
import '../../ui/adaptive/host.dart';
import 'saved_server_editor.dart';
import 'saved_server_row.dart';
import 'server_connections.dart';
@@ -47,47 +45,25 @@ class SavedServersSection extends StatelessWidget {
}
Future<void> _remove(BuildContext context, SavedServer server) async {
final cupertino = usesCupertinoHost(context);
final confirmed = cupertino
? await showCupertinoDialog<bool>(
context: context,
builder: (context) => CupertinoAlertDialog(
title: Text('Remove ${server.name}?'),
content: const Text(
'This removes the saved configuration, not data on the server.',
),
actions: [
CupertinoDialogAction(
onPressed: () => Navigator.pop(context, false),
child: const Text('Cancel'),
),
CupertinoDialogAction(
isDestructiveAction: true,
onPressed: () => Navigator.pop(context, true),
child: const Text('Remove'),
),
],
),
)
: await showDialog<bool>(
context: context,
builder: (context) => AlertDialog(
title: Text('Remove ${server.name}?'),
content: const Text(
'This removes the saved configuration, not data on the server.',
),
actions: [
TextButton(
onPressed: () => Navigator.pop(context, false),
child: const Text('Cancel'),
),
TextButton(
onPressed: () => Navigator.pop(context, true),
child: const Text('Remove'),
),
],
),
);
final confirmed = await showDialog<bool>(
context: context,
builder: (context) => AlertDialog(
title: Text('Remove ${server.name}?'),
content: const Text(
'This removes the saved configuration, not data on the server.',
),
actions: [
TextButton(
onPressed: () => Navigator.pop(context, false),
child: const Text('Cancel'),
),
TextButton(
onPressed: () => Navigator.pop(context, true),
child: const Text('Remove'),
),
],
),
);
if (confirmed == true) await connections.remove(server.id);
}
@@ -116,7 +92,6 @@ class SavedServersSection extends StatelessWidget {
Widget build(BuildContext context) => ListenableBuilder(
listenable: Listenable.merge([connections, ?connections.authenticator]),
builder: (context, _) {
final cupertino = usesCupertinoHost(context);
final error = connections.error;
final allowSelection = allowPrimarySelection ?? !kIsWeb;
return SettingsGroup(
@@ -150,7 +125,7 @@ class SavedServersSection extends StatelessWidget {
SettingsRow(
action: true,
enabled: !connections.busy,
leading: Icon(cupertino ? CupertinoIcons.add : Icons.add),
leading: Icon(Icons.add),
title: const Text('Add server'),
onTap: () => unawaited(_edit(context)),
),
@@ -1,9 +1,7 @@
import 'dart:convert';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import '../../ui/adaptive/host.dart';
import '../artifacts/ui/artifact_external_open.dart';
import '../artifacts/ui/artifact_viewer_fetch.dart';
import '../updates/app_updates.dart';
@@ -71,14 +69,9 @@ class _SettingsAndroidDownloadSectionState
@override
Widget build(BuildContext context) {
final cupertino = usesCupertinoHost(context);
final muted = cupertino
? CupertinoTheme.of(context).textTheme.textStyle.copyWith(
color: CupertinoColors.secondaryLabel.resolveFrom(context),
)
: Theme.of(context).textTheme.bodySmall?.copyWith(
color: Theme.of(context).colorScheme.onSurfaceVariant,
);
final muted = Theme.of(context).textTheme.bodySmall?.copyWith(
color: Theme.of(context).colorScheme.onSurfaceVariant,
);
final update = _update;
if (_loading) {
return Text('Checking for the Android app…', style: muted);
@@ -89,18 +82,12 @@ class _SettingsAndroidDownloadSectionState
style: muted,
);
}
final button = cupertino
? CupertinoButton.filled(
key: const Key('settings-android-download'),
onPressed: () => _download(update),
child: const Text('Download APK'),
)
: FilledButton.icon(
key: const Key('settings-android-download'),
onPressed: () => _download(update),
icon: const Icon(Icons.download),
label: const Text('Download APK'),
);
final button = FilledButton.icon(
key: const Key('settings-android-download'),
onPressed: () => _download(update),
icon: const Icon(Icons.download),
label: const Text('Download APK'),
);
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
@@ -1,5 +1,4 @@
import 'dart:async';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import '../../ui/motion/animation_speed.dart';
import '../../ui/motion/quick_switch_animation.dart';
@@ -20,7 +19,6 @@ class SettingsAnimationSection extends StatelessWidget {
Widget build(BuildContext context) => ListenableBuilder(
listenable: controller,
builder: (context, _) {
final cupertino = usesCupertinoControls(context);
final speed = controller.speed;
final label = '${speed.toStringAsFixed(1)}×';
final reset = speed == 1 ? null : () => unawaited(controller.reset());
@@ -49,39 +47,22 @@ class SettingsAnimationSection extends StatelessWidget {
crossAxisAlignment: WrapCrossAlignment.center,
children: [
Text(label, style: settingsTextStyle(context, title: true)),
cupertino
? CupertinoButton(
onPressed: reset,
child: const Text('Reset'),
)
: TextButton(
onPressed: reset,
child: const Text('Reset'),
),
TextButton(onPressed: reset, child: const Text('Reset')),
],
),
Semantics(
label: 'Animation speed',
child: cupertino
? CupertinoSlider(
value: speed,
min: minAnimationSpeed,
max: maxAnimationSpeed,
divisions: 15,
onChanged: controller.setSpeed,
onChangeEnd: (_) => unawaited(controller.save()),
)
: Slider(
value: speed,
min: minAnimationSpeed,
max: maxAnimationSpeed,
divisions: 15,
label: label,
semanticFormatterCallback: (value) =>
'${value.toStringAsFixed(1)} times',
onChanged: controller.setSpeed,
onChangeEnd: (_) => unawaited(controller.save()),
),
child: Slider(
value: speed,
min: minAnimationSpeed,
max: maxAnimationSpeed,
divisions: 15,
label: label,
semanticFormatterCallback: (value) =>
'${value.toStringAsFixed(1)} times',
onChanged: controller.setSpeed,
onChangeEnd: (_) => unawaited(controller.save()),
),
),
const Wrap(
alignment: WrapAlignment.spaceBetween,
@@ -1,15 +1,13 @@
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.
/// 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 {
@@ -44,58 +42,11 @@ class SettingsTextField extends StatelessWidget {
final labelWidget = ExcludeSemantics(
child: Text(
label,
style: usesCupertinoControls(context)
? settingsTextStyle(context, secondary: true)
: theme.textTheme.labelMedium?.copyWith(
color: theme.colorScheme.onSurfaceVariant,
),
style: 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>[
@@ -103,26 +54,38 @@ class SettingsTextField extends StatelessWidget {
const SizedBox(height: settingsFieldGap),
Semantics(
label: label,
child: CupertinoTextField(
child: TextField(
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,
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(),
),
),
),
],
@@ -152,24 +115,6 @@ class SettingsActions extends StatelessWidget {
@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,
@@ -1,4 +1,3 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import '../../ui/theme/app_font_controller.dart';
@@ -6,7 +5,6 @@ import '../../ui/theme/custom_fonts/custom_font.dart';
import '../../ui/theme/custom_fonts/custom_font_draft.dart';
import '../../ui/theme/custom_fonts/font_file_picker.dart';
import 'settings_custom_font_dialogs.dart';
import 'settings_theme.dart';
const addCustomFontText = 'Add font…';
const addingCustomFontText = 'Adding…';
@@ -104,45 +102,8 @@ class CustomFontMenu extends StatelessWidget {
}
}
Future<void> _cupertinoSheet(BuildContext context) async {
final action = await showCupertinoModalPopup<_CustomFontAction>(
context: context,
builder: (context) => CupertinoActionSheet(
title: Text(font.name),
actions: <Widget>[
CupertinoActionSheetAction(
onPressed: () => Navigator.pop(context, _CustomFontAction.rename),
child: const Text(renameCustomFontText),
),
CupertinoActionSheetAction(
isDestructiveAction: true,
onPressed: () => Navigator.pop(context, _CustomFontAction.remove),
child: const Text(removeCustomFontText),
),
],
cancelButton: CupertinoActionSheetAction(
onPressed: () => Navigator.pop(context),
child: const Text('Cancel'),
),
),
);
if (action != null && context.mounted) await _run(context, action);
}
@override
Widget build(BuildContext context) {
if (usesCupertinoControls(context)) {
return Semantics(
label: customFontActionsTooltip,
button: true,
excludeSemantics: true,
child: CupertinoButton(
padding: EdgeInsets.zero,
onPressed: () => _cupertinoSheet(context),
child: const Icon(CupertinoIcons.ellipsis_circle),
),
);
}
return PopupMenuButton<_CustomFontAction>(
tooltip: customFontActionsTooltip,
onSelected: (action) => _run(context, action),
@@ -1,8 +1,6 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import '../../ui/theme/custom_fonts/custom_font_draft.dart';
import 'settings_theme.dart';
const customFontNameLabel = 'Name';
const addCustomFontTitle = 'Add font';
@@ -24,9 +22,7 @@ Future<String?> showFontNameDialog(
confirm: confirm,
detail: detail,
);
return usesCupertinoControls(context)
? showCupertinoDialog<String>(context: context, builder: (_) => dialog)
: showDialog<String>(context: context, builder: (_) => dialog);
return showDialog<String>(context: context, builder: (_) => dialog);
}
class _FontNameDialog extends StatefulWidget {
@@ -69,25 +65,16 @@ class _FontNameDialogState extends State<_FontNameDialog> {
@override
Widget build(BuildContext context) {
final cupertino = usesCupertinoControls(context);
final field = cupertino
? CupertinoTextField(
controller: _name,
autofocus: true,
placeholder: customFontNameLabel,
maxLength: CustomFontLimits.maxNameLength,
onSubmitted: (_) => _submit(),
)
: TextField(
controller: _name,
autofocus: true,
maxLength: CustomFontLimits.maxNameLength,
decoration: InputDecoration(
labelText: customFontNameLabel,
errorText: _problem,
),
onSubmitted: (_) => _submit(),
);
final field = TextField(
controller: _name,
autofocus: true,
maxLength: CustomFontLimits.maxNameLength,
decoration: InputDecoration(
labelText: customFontNameLabel,
errorText: _problem,
),
onSubmitted: (_) => _submit(),
);
final content = Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.stretch,
@@ -97,30 +84,8 @@ class _FontNameDialogState extends State<_FontNameDialog> {
const SizedBox(height: 12),
],
field,
if (cupertino && _problem != null)
Text(_problem!, style: TextStyle(color: settingsErrorColor(context))),
],
);
if (cupertino) {
return CupertinoAlertDialog(
title: Text(widget.title),
content: Padding(
padding: const EdgeInsets.only(top: 8),
child: content,
),
actions: <Widget>[
CupertinoDialogAction(
onPressed: () => Navigator.pop(context),
child: const Text('Cancel'),
),
CupertinoDialogAction(
isDefaultAction: true,
onPressed: _submit,
child: Text(widget.confirm),
),
],
);
}
return AlertDialog(
title: Text(widget.title),
content: SingleChildScrollView(child: content),
@@ -139,42 +104,23 @@ class _FontNameDialogState extends State<_FontNameDialog> {
Future<bool> confirmRemoveFont(BuildContext context, String name) async {
final title = Text('Remove $name?');
const body = Text('Its files are deleted from this device.');
final confirmed = usesCupertinoControls(context)
? await showCupertinoDialog<bool>(
context: context,
builder: (context) => CupertinoAlertDialog(
title: title,
content: body,
actions: <Widget>[
CupertinoDialogAction(
onPressed: () => Navigator.pop(context, false),
child: const Text('Cancel'),
),
CupertinoDialogAction(
isDestructiveAction: true,
onPressed: () => Navigator.pop(context, true),
child: const Text('Remove'),
),
],
),
)
: await showDialog<bool>(
context: context,
builder: (context) => AlertDialog(
title: title,
content: body,
actions: <Widget>[
TextButton(
onPressed: () => Navigator.pop(context, false),
child: const Text('Cancel'),
),
TextButton(
onPressed: () => Navigator.pop(context, true),
child: const Text('Remove'),
),
],
),
);
final confirmed = await showDialog<bool>(
context: context,
builder: (context) => AlertDialog(
title: title,
content: body,
actions: <Widget>[
TextButton(
onPressed: () => Navigator.pop(context, false),
child: const Text('Cancel'),
),
TextButton(
onPressed: () => Navigator.pop(context, true),
child: const Text('Remove'),
),
],
),
);
return confirmed ?? false;
}
@@ -183,31 +129,16 @@ Future<void> showFontProblem(
BuildContext context,
String title,
String message,
) => usesCupertinoControls(context)
? showCupertinoDialog<void>(
context: context,
builder: (context) => CupertinoAlertDialog(
title: Text(title),
content: Text(message),
actions: <Widget>[
CupertinoDialogAction(
isDefaultAction: true,
onPressed: () => Navigator.pop(context),
child: const Text('OK'),
),
],
),
)
: showDialog<void>(
context: context,
builder: (context) => AlertDialog(
title: Text(title),
content: Text(message),
actions: <Widget>[
TextButton(
onPressed: () => Navigator.pop(context),
child: const Text('OK'),
),
],
),
);
) => showDialog<void>(
context: context,
builder: (context) => AlertDialog(
title: Text(title),
content: Text(message),
actions: <Widget>[
TextButton(
onPressed: () => Navigator.pop(context),
child: const Text('OK'),
),
],
),
);
@@ -1,6 +1,5 @@
import 'dart:async';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import '../notification_service/notification_service_bridge.dart';
@@ -84,7 +83,6 @@ class _SettingsDeviceDeliverySectionState
);
Widget _body(BuildContext context) {
final cupertino = usesCupertinoControls(context);
final status = _controller.status;
final enabled = status?.enabled ?? false;
final onChanged = status == null || _controller.busy
@@ -105,20 +103,12 @@ class _SettingsDeviceDeliverySectionState
],
),
children: <Widget>[
if (cupertino)
CupertinoListTile(
key: DeviceDeliveryKeys.toggle,
title: const Text(deviceDeliverySwitchLabel),
trailing: CupertinoSwitch(value: enabled, onChanged: onChanged),
onTap: onChanged == null ? null : () => onChanged(!enabled),
)
else
SwitchListTile(
key: DeviceDeliveryKeys.toggle,
title: const Text(deviceDeliverySwitchLabel),
value: enabled,
onChanged: onChanged,
),
SwitchListTile(
key: DeviceDeliveryKeys.toggle,
title: const Text(deviceDeliverySwitchLabel),
value: enabled,
onChanged: onChanged,
),
SettingsRow(
key: DeviceDeliveryKeys.status,
title: const Text('Status'),
@@ -1,6 +1,5 @@
import 'dart:async';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import '../../ui/theme/app_font.dart';
@@ -30,7 +29,7 @@ const ValueKey<String> settingsAddFontKey = ValueKey<String>(
/// The device's interface font: one row per option, each named in its own
/// face, the user's added fonts below the bundled ones, then "Add font…".
/// Material rows are radio tiles, Cupertino rows carry the checkmark.
/// Material rows are radio tiles.
/// A choice is stored locally and applies as soon as its files load.
class SettingsFontSection extends StatefulWidget {
const SettingsFontSection({
@@ -98,7 +97,6 @@ class _SettingsFontSectionState extends State<SettingsFontSection> {
Widget _group(BuildContext context) {
final controller = widget.controller;
final cupertino = usesCupertinoControls(context);
final options = <FontChoice>[...AppFont.values, ...controller.customFonts];
final group = SettingsGroup(
title: fontSectionTitle,
@@ -114,10 +112,7 @@ class _SettingsFontSectionState extends State<SettingsFontSection> {
],
),
children: <Widget>[
for (final font in options)
cupertino
? _cupertinoRow(context, font)
: _materialRow(context, font),
for (final font in options) _materialRow(context, font),
// Its own node: a bare list tile would lend its label and tap to the
// section around it.
Semantics(
@@ -126,7 +121,7 @@ class _SettingsFontSectionState extends State<SettingsFontSection> {
key: settingsAddFontKey,
action: true,
enabled: !_adding,
leading: Icon(cupertino ? CupertinoIcons.add : Icons.add),
leading: Icon(Icons.add),
title: const Text(addCustomFontText),
subtitle: _adding ? const Text(addingCustomFontText) : null,
onTap: () => unawaited(_add()),
@@ -134,7 +129,6 @@ class _SettingsFontSectionState extends State<SettingsFontSection> {
),
],
);
if (cupertino) return group;
return RadioGroup<FontChoice>(
groupValue: controller.selected,
onChanged: (font) {
@@ -166,39 +160,6 @@ class _SettingsFontSectionState extends State<SettingsFontSection> {
);
}
Widget _cupertinoRow(BuildContext context, FontChoice font) {
final check = widget.controller.selected == font
? Icon(
CupertinoIcons.check_mark,
color: CupertinoTheme.of(context).primaryColor,
)
: null;
// One node per option, announced as selected.
final row = Semantics(
container: true,
selected: check != null,
child: SettingsRow(
key: settingsFontKey(font),
title: _name(context, font),
subtitle: _status(context, font),
trailing: check,
onTap: () => unawaited(widget.controller.select(font)),
),
);
if (font is! CustomFont) return row;
// Beside the row, not in it: the list tile merges its children's
// semantics (see [_materialRow]).
return Row(
children: <Widget>[
Expanded(child: row),
Padding(
padding: const EdgeInsetsDirectional.only(end: 12),
child: CustomFontMenu(fonts: widget.controller, font: font),
),
],
);
}
/// The option's name in its own face once its regular weight has loaded;
/// the system face until then (and always for the system option).
Widget _name(BuildContext context, FontChoice font) {
@@ -225,10 +186,9 @@ class _SettingsFontSectionState extends State<SettingsFontSection> {
}
}
/// The platform's own interface family (Roboto, or the Cupertino system
/// face), independent of the font the theme currently applies.
String? _systemFamily(BuildContext context) => usesCupertinoControls(context)
? const CupertinoTextThemeData().textStyle.fontFamily
: Typography.material2021(
platform: Theme.of(context).platform,
).black.bodyLarge?.fontFamily;
/// The platform's own interface family (Roboto), independent of the font the
/// theme currently applies.
String? _systemFamily(BuildContext context) =>
Typography.material2021(
platform: Theme.of(context).platform,
).black.bodyLarge?.fontFamily;
+6 -34
View File
@@ -1,18 +1,12 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import '../../ui/theme/app_theme.dart';
import 'settings_layout.dart';
import 'settings_theme.dart';
/// One grouped Settings section: a short header, a flat rounded group of rows
/// and an optional one-line footer.
///
/// Material draws the header in the theme's primary `titleSmall` and the rows
/// on a flat `surfaceContainer` with hairline dividers (no elevation).
/// Cupertino uses the stock inset-grouped [CupertinoListSection], whose rows
/// sit on `secondarySystemGroupedBackground` over the page's
/// `systemGroupedBackground`.
class SettingsGroup extends StatelessWidget {
const SettingsGroup({
super.key,
@@ -28,26 +22,14 @@ class SettingsGroup extends StatelessWidget {
/// A short line (or two) under the group: helper copy, a warning.
final Widget? footer;
/// Whether the rows carry leading icons: Cupertino then starts its
/// dividers at the titles (the stock inset), otherwise at the row text.
/// Whether the rows carry leading icons: kept for callers, the Material
/// group does not depend on it.
final bool leadingRows;
@override
Widget build(BuildContext context) {
final title = this.title;
final footer = this.footer;
if (usesCupertinoControls(context)) {
return CupertinoListSection.insetGrouped(
margin: EdgeInsets.zero,
backgroundColor: AppColors.groupedBackground,
header: title == null
? null
: Text(title, style: settingsHeaderStyle(context)),
footer: footer == null ? null : _footer(context, footer),
additionalDividerMargin: leadingRows ? null : 6,
children: children.isEmpty ? null : children,
);
}
final theme = Theme.of(context);
return Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
@@ -96,17 +78,10 @@ class SettingsGroup extends StatelessWidget {
}
Widget _footer(BuildContext context, Widget footer) {
final cupertino = usesCupertinoControls(context);
// Cupertino: the footnote size the stock plain list section uses for
// its own header and footer.
final style = cupertino
? settingsTextStyle(context, secondary: true).copyWith(fontSize: 13)
: Theme.of(context).textTheme.bodySmall?.copyWith(
color: Theme.of(context).colorScheme.onSurfaceVariant,
);
final style = Theme.of(context).textTheme.bodySmall?.copyWith(
color: Theme.of(context).colorScheme.onSurfaceVariant,
);
final text = DefaultTextStyle.merge(style: style, child: footer);
// The Cupertino section pads its own footer.
if (cupertino) return text;
return Padding(
padding: const EdgeInsetsDirectional.fromSTEB(
settingsRowInset,
@@ -121,9 +96,6 @@ class SettingsGroup extends StatelessWidget {
/// A group header's text style.
TextStyle settingsHeaderStyle(BuildContext context) {
if (usesCupertinoControls(context)) {
return settingsTextStyle(context).copyWith(fontWeight: FontWeight.w600);
}
final theme = Theme.of(context);
return (theme.textTheme.titleSmall ?? const TextStyle()).copyWith(
color: theme.colorScheme.primary,
@@ -142,7 +114,7 @@ class SettingsGroupItem extends StatelessWidget {
width: double.infinity,
child: Padding(
padding: EdgeInsetsDirectional.symmetric(
horizontal: usesCupertinoControls(context) ? 20 : settingsRowInset,
horizontal: settingsRowInset,
vertical: 12,
),
child: child,
@@ -1,8 +1,8 @@
/// The one place the Settings screen keeps its necessary layout constraints.
///
/// Everything else (control heights, font sizes, colours, button padding) comes
/// from the active Material or Cupertino theme, so text scaling and platform
/// defaults are never overridden here.
/// from the active Material theme, so text scaling and platform defaults are
/// never overridden here.
///
/// The page is a column of grouped sections. It starts at the top bar's own
/// side inset, so on a wide window the groups line up under the title pill
@@ -1,6 +1,5 @@
import 'dart:async';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import '../../core/api_gateway.dart';
@@ -82,7 +81,6 @@ class _SettingsNtfySectionState extends State<SettingsNtfySection> {
);
Widget _body(BuildContext context) {
final cupertino = usesCupertinoControls(context);
final values = _controller.values;
final enabled = widget.connected && _controller.enabled;
final status = !widget.connected
@@ -97,7 +95,6 @@ class _SettingsNtfySectionState extends State<SettingsNtfySection> {
if (hasNtfySwitch) ntfyEnabledSetting,
])
_tile(
cupertino,
setting,
values?[setting.key] ?? false,
enabled ? (value) => _controller.toggle(setting.key, value) : null,
@@ -123,16 +120,10 @@ class _SettingsNtfySectionState extends State<SettingsNtfySection> {
if (_controller.error.isNotEmpty && retry)
Align(
alignment: AlignmentDirectional.centerStart,
child: cupertino
? CupertinoButton(
padding: EdgeInsets.zero,
onPressed: _controller.load,
child: const Text('Retry'),
)
: TextButton(
onPressed: _controller.load,
child: const Text('Retry'),
),
child: TextButton(
onPressed: _controller.load,
child: const Text('Retry'),
),
),
],
),
@@ -141,22 +132,10 @@ class _SettingsNtfySectionState extends State<SettingsNtfySection> {
}
Widget _tile(
bool cupertino,
NtfySetting setting,
bool value,
ValueChanged<bool>? onChanged,
) {
if (cupertino) {
return CupertinoListTile(
key: ntfySettingKey(setting.key),
title: Text(setting.label),
subtitle: setting.subtitle == null ? null : Text(setting.subtitle!),
// iOS settings rows toggle with a switch; an unchecked checkbox is
// nearly invisible on the grouped row.
trailing: CupertinoSwitch(value: value, onChanged: onChanged),
onTap: onChanged == null ? null : () => onChanged(!value),
);
}
return CheckboxListTile(
key: ntfySettingKey(setting.key),
title: Text(setting.label),