Merge main into chat tab re-tap
This commit is contained in:
@@ -28,6 +28,7 @@ import '../features/runs/ui/run_search_selection.dart';
|
||||
import '../features/search/domain/search_target.dart';
|
||||
import '../features/settings/settings_screen.dart';
|
||||
import '../features/settings/settings_store.dart';
|
||||
import '../features/walkthrough/first_run_walkthrough.dart';
|
||||
import '../features/walkthrough/walkthrough_gate.dart';
|
||||
import '../features/walkthrough/walkthrough_store.dart';
|
||||
import '../features/updates/app_updates.dart';
|
||||
@@ -945,9 +946,8 @@ class _PipelinesAppState extends State<PipelinesApp>
|
||||
),
|
||||
// Settings is a page of the Pipelines tab (its bar's gear), not a
|
||||
// tab; the shell shows it with Back to Pipelines.
|
||||
AppDestination.settings: (_) => SettingsScreen(
|
||||
AppDestination.settings: (context) => SettingsScreen(
|
||||
terminalLayout: _terminals.layout,
|
||||
navigationScope: _navigationScope,
|
||||
client: _session.client,
|
||||
// A phone signs in at the web login; a browser has its own.
|
||||
showSignIn: !kIsWeb,
|
||||
@@ -961,6 +961,9 @@ class _PipelinesAppState extends State<PipelinesApp>
|
||||
notifications: _notifications,
|
||||
deliveryService: _deliveryService,
|
||||
deliveryServiceController: _deliveryController,
|
||||
// The Help and about row replays the first-run walkthrough. It only
|
||||
// shows it; the device's seen record is left alone.
|
||||
onShowWalkthrough: () => unawaited(showFirstRunWalkthrough(context)),
|
||||
),
|
||||
},
|
||||
);
|
||||
|
||||
@@ -50,6 +50,7 @@ class NtfySettingsController extends ChangeNotifier {
|
||||
bool _loading = false;
|
||||
String? _saving;
|
||||
String _error = '';
|
||||
bool _loadFailed = false;
|
||||
bool _disposed = false;
|
||||
|
||||
/// The stored values, or null before the first successful load.
|
||||
@@ -60,6 +61,9 @@ class NtfySettingsController extends ChangeNotifier {
|
||||
String? get saving => _saving;
|
||||
String get error => _error;
|
||||
|
||||
/// Whether the latest load failed; the stored values, if any, are kept.
|
||||
bool get loadFailed => _loadFailed;
|
||||
|
||||
/// Whether the checkboxes accept a change now.
|
||||
bool get enabled => _values != null && !_loading && _saving == null;
|
||||
|
||||
@@ -67,11 +71,13 @@ class NtfySettingsController extends ChangeNotifier {
|
||||
if (_loading) return;
|
||||
_loading = true;
|
||||
_error = '';
|
||||
_loadFailed = false;
|
||||
_notify();
|
||||
try {
|
||||
final reply = await gateway.call('notification_settings');
|
||||
_values = _decode(reply);
|
||||
} catch (error) {
|
||||
_loadFailed = true;
|
||||
_error = 'Could not load notification settings: $error';
|
||||
} finally {
|
||||
_loading = false;
|
||||
|
||||
@@ -1,7 +1,12 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../../../core/session/server_session.dart';
|
||||
import '../settings_layout.dart';
|
||||
import '../settings_server_load.dart';
|
||||
import '../settings_server_view.dart';
|
||||
import 'session_security_api.dart';
|
||||
|
||||
/// The server's sign-in security: a warning when its password predates the
|
||||
@@ -30,40 +35,47 @@ class SettingsSecuritySection extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _SettingsSecuritySectionState extends State<SettingsSecuritySection> {
|
||||
SessionSecurity? _security;
|
||||
// One load per endpoint, created in initState: rebuilding never refetches.
|
||||
late ServerLoad<SessionSecurity> _security = _loaderFor(widget.endpoint);
|
||||
String? _message;
|
||||
bool _busy = false;
|
||||
Timer? _endpointSettle;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_load();
|
||||
}
|
||||
// The view starts the load when the section mounts (a lazy page section).
|
||||
ServerLoad<SessionSecurity> _loaderFor(String endpoint) =>
|
||||
ServerLoad(() => loadSessionSecurity(endpoint));
|
||||
|
||||
@override
|
||||
void didUpdateWidget(SettingsSecuritySection oldWidget) {
|
||||
super.didUpdateWidget(oldWidget);
|
||||
if (oldWidget.endpoint != widget.endpoint) _load();
|
||||
}
|
||||
|
||||
Future<void> _load() async {
|
||||
final endpoint = widget.endpoint;
|
||||
try {
|
||||
final security = await loadSessionSecurity(endpoint);
|
||||
if (!mounted || endpoint != widget.endpoint) return;
|
||||
setState(() {
|
||||
_security = security;
|
||||
_message = null;
|
||||
});
|
||||
} on SessionSecurityException catch (error) {
|
||||
if (!mounted || endpoint != widget.endpoint) return;
|
||||
setState(() {
|
||||
_security = null;
|
||||
_message = error.message;
|
||||
});
|
||||
// The endpoint follows the URL draft while it is typed; wait until it
|
||||
// settles so each keystroke does not start a request.
|
||||
if (oldWidget.endpoint != widget.endpoint) {
|
||||
_endpointSettle?.cancel();
|
||||
_endpointSettle = Timer(settingsEndpointDebounce, _switchEndpoint);
|
||||
}
|
||||
}
|
||||
|
||||
void _switchEndpoint() {
|
||||
if (!mounted) return;
|
||||
setState(() {
|
||||
_security.dispose();
|
||||
_message = null;
|
||||
_security = _loaderFor(widget.endpoint);
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_endpointSettle?.cancel();
|
||||
_security.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
static String _describe(Object error) => error is SessionSecurityException
|
||||
? error.message
|
||||
: 'Could not read sign-in security: $error';
|
||||
|
||||
Future<bool> _confirm() async {
|
||||
const title = Text('Sign out everywhere?');
|
||||
const body = Text(
|
||||
@@ -123,7 +135,6 @@ class _SettingsSecuritySectionState extends State<SettingsSecuritySection> {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final security = _security;
|
||||
final button = OutlinedButton(
|
||||
key: const Key('settings-revoke-all'),
|
||||
onPressed: _busy ? null : _revokeAll,
|
||||
@@ -132,16 +143,22 @@ class _SettingsSecuritySectionState extends State<SettingsSecuritySection> {
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
if (security != null && security.weakPassword)
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(bottom: 8),
|
||||
child: Text(
|
||||
key: const Key('settings-weak-password'),
|
||||
'This server\'s sign-in password is weak. '
|
||||
'${security.rule.isEmpty ? '' : '${security.rule} '}'
|
||||
'Run ./password on the server to choose a stronger one.',
|
||||
),
|
||||
),
|
||||
ServerSettingsView<SessionSecurity>(
|
||||
load: _security,
|
||||
describe: _describe,
|
||||
retryKey: const Key('settings-security-retry'),
|
||||
builder: (context, security) => security.weakPassword
|
||||
? Padding(
|
||||
padding: const EdgeInsets.only(bottom: 8),
|
||||
child: Text(
|
||||
key: const Key('settings-weak-password'),
|
||||
'This server\'s sign-in password is weak. '
|
||||
'${security.rule.isEmpty ? '' : '${security.rule} '}'
|
||||
'Run ./password on the server to choose a stronger one.',
|
||||
),
|
||||
)
|
||||
: const SizedBox.shrink(),
|
||||
),
|
||||
const Text(
|
||||
'Signing out everywhere ends every session of this server\'s web '
|
||||
'login. Changing the password with ./password does the same.',
|
||||
|
||||
@@ -13,5 +13,5 @@ abstract final class SettingsKeys {
|
||||
static const keyboardShortcuts = ValueKey<String>(
|
||||
'settings.keyboardShortcuts',
|
||||
);
|
||||
static const walkthrough = ValueKey<String>('settings.walkthrough');
|
||||
static const showWalkthrough = ValueKey<String>('settings.showWalkthrough');
|
||||
}
|
||||
|
||||
@@ -4,9 +4,9 @@
|
||||
/// 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
|
||||
/// instead of floating in the middle, and stops growing at a reading width.
|
||||
/// The page is a column of grouped sections. On a narrow window it fills the
|
||||
/// width inside the top bar's own side inset; on a wide window it is centred
|
||||
/// at a reading width beside the section index.
|
||||
library;
|
||||
|
||||
/// The widest the column of groups grows on a wide window.
|
||||
@@ -39,3 +39,14 @@ const double settingsRowInset = 16;
|
||||
|
||||
/// The corner radius of a Material group.
|
||||
const double settingsGroupRadius = 16;
|
||||
|
||||
/// The wide layout's jump index: shown beside the list from this body width,
|
||||
/// and [settingsIndexWidth] wide.
|
||||
const double settingsIndexMinWidth = 840;
|
||||
const double settingsIndexWidth = 176;
|
||||
|
||||
/// How far below the viewport a lazy section starts loading, in viewports.
|
||||
const double settingsPreloadViewports = 1;
|
||||
|
||||
/// How long a changing endpoint must settle before a server section reloads.
|
||||
const Duration settingsEndpointDebounce = Duration(milliseconds: 600);
|
||||
|
||||
@@ -100,7 +100,11 @@ class _SettingsNtfySectionState extends State<SettingsNtfySection> {
|
||||
enabled ? (value) => _controller.toggle(setting.key, value) : null,
|
||||
),
|
||||
];
|
||||
final retry = values == null && widget.connected && !_controller.loading;
|
||||
// A failed refresh keeps the last values and offers Retry beside them.
|
||||
final retry =
|
||||
widget.connected &&
|
||||
!_controller.loading &&
|
||||
(values == null || _controller.loadFailed);
|
||||
return SettingsGroup(
|
||||
title: ntfySectionTitle,
|
||||
footer: Column(
|
||||
@@ -131,11 +135,7 @@ class _SettingsNtfySectionState extends State<SettingsNtfySection> {
|
||||
);
|
||||
}
|
||||
|
||||
Widget _tile(
|
||||
NtfySetting setting,
|
||||
bool value,
|
||||
ValueChanged<bool>? onChanged,
|
||||
) {
|
||||
Widget _tile(NtfySetting setting, bool value, ValueChanged<bool>? onChanged) {
|
||||
return CheckboxListTile(
|
||||
key: ntfySettingKey(setting.key),
|
||||
title: Text(setting.label),
|
||||
|
||||
@@ -0,0 +1,79 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'settings_section.dart';
|
||||
|
||||
/// The Settings search field: filters the sections as the operator types.
|
||||
class SettingsSearchField extends StatelessWidget {
|
||||
const SettingsSearchField({
|
||||
super.key,
|
||||
required this.controller,
|
||||
required this.onChanged,
|
||||
});
|
||||
|
||||
final TextEditingController controller;
|
||||
final ValueChanged<String> onChanged;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) =>
|
||||
ValueListenableBuilder<TextEditingValue>(
|
||||
valueListenable: controller,
|
||||
builder: (context, value, _) => TextField(
|
||||
key: const ValueKey<String>('settings.search'),
|
||||
controller: controller,
|
||||
onChanged: onChanged,
|
||||
textInputAction: TextInputAction.search,
|
||||
decoration: InputDecoration(
|
||||
hintText: 'Search settings',
|
||||
prefixIcon: const Icon(Icons.search),
|
||||
suffixIcon: value.text.isEmpty
|
||||
? null
|
||||
: IconButton(
|
||||
tooltip: 'Clear search',
|
||||
icon: const Icon(Icons.close),
|
||||
onPressed: () {
|
||||
controller.clear();
|
||||
onChanged('');
|
||||
},
|
||||
),
|
||||
border: const OutlineInputBorder(),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// The wide layout's slim jump index: one link per visible section.
|
||||
class SettingsSectionIndex extends StatelessWidget {
|
||||
const SettingsSectionIndex({
|
||||
super.key,
|
||||
required this.sections,
|
||||
required this.onJump,
|
||||
});
|
||||
|
||||
final List<SettingsSection> sections;
|
||||
final ValueChanged<String> onJump;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => Semantics(
|
||||
container: true,
|
||||
label: 'Settings sections',
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: <Widget>[
|
||||
for (final section in sections)
|
||||
TextButton(
|
||||
key: ValueKey<String>('settings.index.${section.id}'),
|
||||
onPressed: () => onJump(section.id),
|
||||
style: TextButton.styleFrom(
|
||||
alignment: AlignmentDirectional.centerStart,
|
||||
),
|
||||
child: Text(
|
||||
section.title,
|
||||
textAlign: TextAlign.start,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,224 @@
|
||||
part of 'settings_screen.dart';
|
||||
|
||||
/// The Settings page's sections, in order. Each entry keeps the widgets the
|
||||
/// former category pages held; a server-backed entry is `lazy`.
|
||||
extension _SettingsPageSections on _SettingsScreenState {
|
||||
List<SettingsSection> _pageSections() {
|
||||
final servers = widget.servers;
|
||||
return [
|
||||
SettingsSection(
|
||||
id: 'interface-size',
|
||||
title: 'Interface size',
|
||||
keywords: 'text size scale zoom large small font',
|
||||
builder: (_) => const SettingsScaleSection(),
|
||||
),
|
||||
SettingsSection(
|
||||
id: 'animations',
|
||||
title: 'Animations',
|
||||
keywords: 'animation speed motion quick switch',
|
||||
builder: (_) => SettingsAnimationSection(
|
||||
controller:
|
||||
widget.animationSpeed ?? AnimationSpeedController.instance,
|
||||
),
|
||||
),
|
||||
SettingsSection(
|
||||
id: 'font',
|
||||
title: fontSectionTitle,
|
||||
keywords: 'font typeface custom text',
|
||||
builder: (_) => SettingsFontSection(
|
||||
controller: widget.fonts ?? AppFontController.instance,
|
||||
),
|
||||
),
|
||||
SettingsSection(
|
||||
id: 'terminal',
|
||||
title: 'Terminal',
|
||||
keywords: 'terminal layout mode split',
|
||||
builder: (_) => SettingsTerminalSection(
|
||||
layout: widget.terminalLayout ?? TerminalLayout.instance,
|
||||
),
|
||||
),
|
||||
if (servers != null) ...[
|
||||
SettingsSection(
|
||||
id: 'servers',
|
||||
title: 'Servers',
|
||||
keywords: 'saved server profile add remove switch address',
|
||||
builder: (_) => SavedServersSection(connections: servers),
|
||||
),
|
||||
SettingsSection(
|
||||
id: 'managed-connection',
|
||||
title: 'Connection',
|
||||
keywords: 'address current reconnect disconnect status',
|
||||
builder: (_) => ManagedConnectionSection(
|
||||
client: widget.client,
|
||||
controller: _controller,
|
||||
),
|
||||
),
|
||||
] else
|
||||
SettingsSection(
|
||||
id: 'connection',
|
||||
title: 'Connection',
|
||||
keywords: 'server url address connect disconnect reconnect status',
|
||||
builder: (_) => SettingsConnectionSection(
|
||||
controller: _controller,
|
||||
serverUrlField: _serverUrlField,
|
||||
),
|
||||
),
|
||||
if (widget.showSignIn)
|
||||
SettingsSection(
|
||||
id: 'sign-in',
|
||||
title: 'Sign in',
|
||||
keywords: 'login password web account',
|
||||
builder: (_) => _single(
|
||||
'Sign in',
|
||||
SettingsSignInSection(
|
||||
endpoint: _endpoint,
|
||||
onChanged: _reconnectAfterSignIn,
|
||||
),
|
||||
),
|
||||
),
|
||||
if (widget.showSignIn || kIsWeb)
|
||||
SettingsSection(
|
||||
id: 'sign-in-security',
|
||||
title: 'Sign-in security',
|
||||
keywords: 'password sessions sign out everywhere revoke weak',
|
||||
lazy: true,
|
||||
builder: (_) => _single(
|
||||
'Sign-in security',
|
||||
SettingsSecuritySection(
|
||||
endpoint: _endpoint,
|
||||
onSignedOut: _reconnectAfterSignIn,
|
||||
),
|
||||
),
|
||||
),
|
||||
SettingsSection(
|
||||
id: 'workspace',
|
||||
title: 'Workspace',
|
||||
keywords: 'workspace path folder directory server save',
|
||||
builder: (_) => SettingsWorkspaceSection(
|
||||
controller: _controller,
|
||||
workspaceField: _workspaceField,
|
||||
),
|
||||
),
|
||||
if (widget.notifications case final notifications?)
|
||||
SettingsSection(
|
||||
id: 'notifications',
|
||||
title: notificationSectionTitle,
|
||||
keywords: 'notification permission browser alerts enable',
|
||||
builder: (_) =>
|
||||
SettingsNotificationsSection(controller: notifications),
|
||||
),
|
||||
if (widget.deliveryService case final service? when service.supported)
|
||||
SettingsSection(
|
||||
id: 'device-delivery',
|
||||
title: deviceDeliveryTitle,
|
||||
keywords: 'background delivery battery android notifications',
|
||||
builder: (_) => SettingsDeviceDeliverySection(
|
||||
bridge: service,
|
||||
controller: widget.deliveryServiceController,
|
||||
requestNotificationPermission: widget.notifications == null
|
||||
? null
|
||||
: () async {
|
||||
await widget.notifications!.requestPermission();
|
||||
},
|
||||
),
|
||||
),
|
||||
SettingsSection(
|
||||
id: 'phone-notifications',
|
||||
title: ntfySectionTitle,
|
||||
keywords: 'ntfy push phone run finished chat needs you',
|
||||
lazy: true,
|
||||
builder: (_) => SettingsNtfySection(
|
||||
gateway: widget.client,
|
||||
connected:
|
||||
widget.client.state.kind == transport.ConnectionKind.connected,
|
||||
),
|
||||
),
|
||||
SettingsSection(
|
||||
id: 'data',
|
||||
title: 'Data management',
|
||||
keywords: 'storage retention worktrees cleanup disk usage',
|
||||
builder: (_) => _single(
|
||||
'Data management',
|
||||
SettingsStorageSection(gateway: widget.client),
|
||||
),
|
||||
),
|
||||
SettingsSection(
|
||||
id: 'server',
|
||||
title: 'Server',
|
||||
keywords: 'health cpu memory gpu process stats',
|
||||
builder: (_) =>
|
||||
_single('Server', SettingsHealthSection(gateway: widget.client)),
|
||||
),
|
||||
if (widget.onOpenSchedules case final open?)
|
||||
SettingsSection(
|
||||
id: 'library',
|
||||
title: 'Library',
|
||||
keywords: 'schedules saved runs pipelines',
|
||||
builder: (_) => SettingsGroup(
|
||||
title: 'Library',
|
||||
leadingRows: true,
|
||||
children: [SettingsSchedulesSection(onOpen: open)],
|
||||
),
|
||||
),
|
||||
if (widget.showAndroidDownload)
|
||||
SettingsSection(
|
||||
id: 'android-app',
|
||||
title: 'Android app',
|
||||
keywords: 'apk download install',
|
||||
builder: (_) =>
|
||||
_single('Android app', const SettingsAndroidDownloadSection()),
|
||||
),
|
||||
if (widget.showSignIn && appUpdatesSupported)
|
||||
SettingsSection(
|
||||
id: 'app-updates',
|
||||
title: 'App updates',
|
||||
keywords: 'update version build install',
|
||||
builder: (_) => _single(
|
||||
'App updates',
|
||||
SettingsUpdatesSection(endpoint: _endpoint, servers: servers),
|
||||
),
|
||||
)
|
||||
else if (!widget.showAndroidDownload)
|
||||
SettingsSection(
|
||||
id: 'app-updates-managed',
|
||||
title: 'App updates',
|
||||
keywords: 'update version build administrator',
|
||||
builder: (_) => _single(
|
||||
'App updates',
|
||||
const Text(
|
||||
'This installation is updated by its server administrator.',
|
||||
),
|
||||
),
|
||||
),
|
||||
// Help and about: the walkthrough's "Show the walkthrough" row sits in
|
||||
// this group beside the keyboard shortcuts.
|
||||
SettingsSection(
|
||||
id: 'help',
|
||||
title: 'Help and about',
|
||||
keywords: 'keyboard shortcuts help about walkthrough tour guide',
|
||||
builder: (_) => SettingsGroup(
|
||||
title: 'Help and about',
|
||||
leadingRows: true,
|
||||
children: [
|
||||
const SettingsKeyboardShortcutsSection(),
|
||||
SettingsRow(
|
||||
key: SettingsKeys.showWalkthrough,
|
||||
leading: const Icon(Icons.school_outlined),
|
||||
title: const Text('Show the walkthrough'),
|
||||
subtitle: const Text('Replay the short tour of Pipelines.'),
|
||||
chevron: true,
|
||||
enabled: widget.onShowWalkthrough != null,
|
||||
onTap: widget.onShowWalkthrough,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
];
|
||||
}
|
||||
|
||||
/// A group holding one free-form block (a form, a status with buttons).
|
||||
Widget _single(String title, Widget child) => SettingsGroup(
|
||||
title: title,
|
||||
children: <Widget>[SettingsGroupItem(child: child)],
|
||||
);
|
||||
}
|
||||
@@ -8,6 +8,7 @@ import 'package:flutter/material.dart';
|
||||
|
||||
import '../../core/transport/pipelines_client.dart' as transport;
|
||||
import '../attention/notify/notification_controller.dart';
|
||||
import '../attention/notify/notification_models.dart';
|
||||
import 'default_endpoint.dart';
|
||||
import 'settings_controller.dart';
|
||||
import 'settings_font_section.dart';
|
||||
@@ -18,8 +19,8 @@ import '../../ui/theme/app_font_controller.dart';
|
||||
import 'settings_group.dart';
|
||||
import 'storage/settings_storage_section.dart';
|
||||
import 'health/settings_health_section.dart';
|
||||
import 'settings_page_body.dart';
|
||||
import 'settings_tabs.dart';
|
||||
import 'settings_search_page.dart';
|
||||
import 'settings_section.dart';
|
||||
import 'settings_notifications_section.dart';
|
||||
import 'settings_ntfy_section.dart';
|
||||
import 'settings_device_delivery_section.dart';
|
||||
@@ -37,12 +38,15 @@ import 'server_connections.dart';
|
||||
import 'saved_servers_section.dart';
|
||||
import 'managed_connection_section.dart';
|
||||
import 'settings_keyboard_shortcuts_section.dart';
|
||||
import 'settings_walkthrough_section.dart';
|
||||
import 'settings_keys.dart';
|
||||
import 'settings_row.dart';
|
||||
|
||||
part 'settings_topic_pages.dart';
|
||||
part 'settings_page_sections.dart';
|
||||
|
||||
/// The Settings destination: the server connection and the server-side
|
||||
/// workspace in native Material controls.
|
||||
/// The Settings destination: one searchable page of grouped Material sections.
|
||||
///
|
||||
/// Local settings render at once. Server-backed sections load lazily (see
|
||||
/// [SettingsSearchPage]) and never block the page.
|
||||
///
|
||||
/// The shared [transport.PipelinesClient] is supplied by the shell. This screen
|
||||
/// subscribes to it, connects/disconnects it and pings it on connected, but it
|
||||
@@ -57,7 +61,6 @@ class SettingsScreen extends StatefulWidget {
|
||||
this.store,
|
||||
this.ping,
|
||||
this.embedded = false,
|
||||
this.navigationScope,
|
||||
this.onOpenSchedules,
|
||||
this.notifications,
|
||||
this.showSignIn = false,
|
||||
@@ -68,8 +71,13 @@ class SettingsScreen extends StatefulWidget {
|
||||
this.fonts,
|
||||
this.animationSpeed,
|
||||
this.terminalLayout,
|
||||
this.onShowWalkthrough,
|
||||
});
|
||||
|
||||
/// Opens the first-run walkthrough from the Help and about group. Null
|
||||
/// leaves the row present but disabled.
|
||||
final VoidCallback? onShowWalkthrough;
|
||||
|
||||
/// The device's interface font; defaults to the app's shared controller.
|
||||
final AppFontController? fonts;
|
||||
final AnimationSpeedController? animationSpeed;
|
||||
@@ -104,9 +112,6 @@ class SettingsScreen extends StatefulWidget {
|
||||
/// The application shell already owns the native navigation bar and safe area.
|
||||
final bool embedded;
|
||||
|
||||
/// The logical server scope used to restore the last Settings category.
|
||||
final String? navigationScope;
|
||||
|
||||
/// Opens the saved-schedule list above Settings.
|
||||
final VoidCallback? onOpenSchedules;
|
||||
|
||||
@@ -179,15 +184,26 @@ class _SettingsScreenState extends State<SettingsScreen> {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final content = SettingsTopicTabs(
|
||||
pages: _topicPages(),
|
||||
navigationScope: widget.navigationScope,
|
||||
);
|
||||
if (widget.embedded) return content;
|
||||
final page = SettingsSearchPage(sections: _pageSections());
|
||||
if (widget.embedded) {
|
||||
// The shell's floating tab bar sits over this body, and the body reads
|
||||
// the bar's height as its bottom padding. The page's rows are controls
|
||||
// and text, so they stop at the bar's top edge instead of scrolling
|
||||
// under the glass where they cannot be read. The reserved space is
|
||||
// removed from the page's own inset so it is not counted twice.
|
||||
return Padding(
|
||||
padding: EdgeInsets.only(bottom: MediaQuery.paddingOf(context).bottom),
|
||||
child: MediaQuery.removePadding(
|
||||
context: context,
|
||||
removeBottom: true,
|
||||
child: SafeArea(bottom: false, child: page),
|
||||
),
|
||||
);
|
||||
}
|
||||
return Scaffold(
|
||||
extendBodyBehindAppBar: true,
|
||||
appBar: const SegmentedBar(title: 'Settings'),
|
||||
body: content,
|
||||
body: SafeArea(bottom: false, child: page),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,226 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'settings_layout.dart';
|
||||
import 'settings_page_chrome.dart';
|
||||
import 'settings_section.dart';
|
||||
import 'settings_skeleton.dart';
|
||||
|
||||
/// The one Settings page: a pinned search field over a scrolling column of
|
||||
/// grouped sections, with a jump index beside it on wide layouts.
|
||||
///
|
||||
/// Local sections render at once. A [SettingsSection.lazy] section shows a
|
||||
/// skeleton until the list scrolls within a viewport of it or a search matches
|
||||
/// it; once reached it stays mounted, so its loaded value survives scrolling.
|
||||
class SettingsSearchPage extends StatefulWidget {
|
||||
const SettingsSearchPage({super.key, required this.sections});
|
||||
|
||||
final List<SettingsSection> sections;
|
||||
|
||||
@override
|
||||
State<SettingsSearchPage> createState() => _SettingsSearchPageState();
|
||||
}
|
||||
|
||||
class _SettingsSearchPageState extends State<SettingsSearchPage> {
|
||||
final TextEditingController _search = TextEditingController();
|
||||
final ScrollController _scroll = ScrollController();
|
||||
final GlobalKey _viewport = GlobalKey();
|
||||
final Map<String, GlobalKey> _keys = {};
|
||||
final Set<String> _activated = {};
|
||||
String _query = '';
|
||||
bool _activationScheduled = false;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_scheduleActivation();
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_search.dispose();
|
||||
_scroll.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
bool get _searching => _query.trim().isNotEmpty;
|
||||
|
||||
List<SettingsSection> get _visible => [
|
||||
for (final section in widget.sections)
|
||||
if (section.matches(_query)) section,
|
||||
];
|
||||
|
||||
GlobalKey _keyFor(String id) => _keys.putIfAbsent(id, GlobalKey.new);
|
||||
|
||||
bool _isActive(SettingsSection section) =>
|
||||
!section.lazy || _activated.contains(section.id) || _searching;
|
||||
|
||||
void _onQueryChanged(String value) {
|
||||
setState(() {
|
||||
_query = value;
|
||||
if (_searching) {
|
||||
_activated.addAll([
|
||||
for (final section in _visible)
|
||||
if (section.lazy) section.id,
|
||||
]);
|
||||
}
|
||||
});
|
||||
_scheduleActivation(jumpToFirstMatch: true);
|
||||
}
|
||||
|
||||
/// Activation and jumps run after the frame: they read layout, and a scroll
|
||||
/// notification may arrive during layout.
|
||||
void _scheduleActivation({bool jumpToFirstMatch = false}) {
|
||||
if (_activationScheduled) return;
|
||||
_activationScheduled = true;
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
_activationScheduled = false;
|
||||
if (!mounted) return;
|
||||
if (jumpToFirstMatch) _jumpForQuery();
|
||||
_activateNear();
|
||||
});
|
||||
}
|
||||
|
||||
void _jumpForQuery() {
|
||||
if (_searching) {
|
||||
final first = _visible.firstOrNull;
|
||||
if (first != null) _jumpTo(first.id);
|
||||
} else if (_scroll.hasClients) {
|
||||
unawaited(
|
||||
_scroll.animateTo(
|
||||
0,
|
||||
duration: const Duration(milliseconds: 200),
|
||||
curve: Curves.easeOut,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
void _jumpTo(String id) {
|
||||
final context = _keys[id]?.currentContext;
|
||||
if (context == null) return;
|
||||
unawaited(
|
||||
Scrollable.ensureVisible(
|
||||
context,
|
||||
duration: const Duration(milliseconds: 250),
|
||||
curve: Curves.easeOut,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _activateNear() {
|
||||
final viewport = _viewport.currentContext?.findRenderObject();
|
||||
if (viewport is! RenderBox || !viewport.hasSize) return;
|
||||
final top = viewport.localToGlobal(Offset.zero).dy;
|
||||
final limit = top + viewport.size.height * (1 + settingsPreloadViewports);
|
||||
var changed = false;
|
||||
for (final section in widget.sections) {
|
||||
if (!section.lazy || _activated.contains(section.id)) continue;
|
||||
final box = _keys[section.id]?.currentContext?.findRenderObject();
|
||||
if (box is! RenderBox || !box.hasSize || !box.attached) continue;
|
||||
if (box.localToGlobal(Offset.zero).dy <= limit) {
|
||||
_activated.add(section.id);
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
if (changed) setState(() {});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final insets = MediaQuery.paddingOf(context);
|
||||
final visible = _visible;
|
||||
return LayoutBuilder(
|
||||
builder: (context, constraints) {
|
||||
final wide = constraints.maxWidth >= settingsIndexMinWidth;
|
||||
return Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: <Widget>[
|
||||
Expanded(
|
||||
child: Padding(
|
||||
padding: EdgeInsetsDirectional.fromSTEB(
|
||||
insets.left + settingsPageSidePadding,
|
||||
insets.top + settingsPageTopPadding,
|
||||
insets.right + settingsPageSidePadding,
|
||||
0,
|
||||
),
|
||||
child: Align(
|
||||
alignment: Alignment.topCenter,
|
||||
child: ConstrainedBox(
|
||||
constraints: const BoxConstraints(
|
||||
maxWidth: settingsContentMaxWidth,
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: <Widget>[
|
||||
SettingsSearchField(
|
||||
controller: _search,
|
||||
onChanged: _onQueryChanged,
|
||||
),
|
||||
const SizedBox(height: settingsSectionGap),
|
||||
Expanded(child: _list(visible, insets)),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
if (wide && visible.isNotEmpty)
|
||||
SizedBox(
|
||||
width: settingsIndexWidth,
|
||||
child: Padding(
|
||||
padding: EdgeInsetsDirectional.only(
|
||||
top: insets.top + settingsPageTopPadding,
|
||||
),
|
||||
child: SettingsSectionIndex(
|
||||
sections: visible,
|
||||
onJump: _jumpTo,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Widget _list(List<SettingsSection> visible, EdgeInsets insets) {
|
||||
if (visible.isEmpty) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.all(settingsRowInset),
|
||||
child: Text('No settings match "${_search.text.trim()}".'),
|
||||
);
|
||||
}
|
||||
return NotificationListener<ScrollNotification>(
|
||||
onNotification: (_) {
|
||||
_scheduleActivation();
|
||||
return false;
|
||||
},
|
||||
child: KeyedSubtree(
|
||||
key: _viewport,
|
||||
child: SingleChildScrollView(
|
||||
key: const ValueKey<String>('settings.scroll'),
|
||||
controller: _scroll,
|
||||
padding: EdgeInsets.only(
|
||||
bottom: insets.bottom + settingsPageBottomPadding,
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: <Widget>[
|
||||
for (final (index, section) in visible.indexed) ...<Widget>[
|
||||
if (index > 0) const SizedBox(height: settingsSectionGap),
|
||||
KeyedSubtree(
|
||||
key: _keyFor(section.id),
|
||||
child: _isActive(section)
|
||||
? Builder(builder: section.builder)
|
||||
: SettingsSkeleton(title: section.title),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
import 'package:flutter/widgets.dart';
|
||||
|
||||
/// One headed group of the single Settings page.
|
||||
///
|
||||
/// A section is searchable by its [title] and [keywords], listed in the wide
|
||||
/// layout's jump index, and built on demand when it is [lazy]: a server-backed
|
||||
/// section shows a skeleton until the page is scrolled near it or a search
|
||||
/// matches it, so the page never waits for the server.
|
||||
class SettingsSection {
|
||||
const SettingsSection({
|
||||
required this.id,
|
||||
required this.title,
|
||||
required this.builder,
|
||||
this.keywords = '',
|
||||
this.lazy = false,
|
||||
});
|
||||
|
||||
/// A stable identifier for keys and jump links.
|
||||
final String id;
|
||||
|
||||
/// The heading shown in the index, the skeleton and the group.
|
||||
final String title;
|
||||
|
||||
/// Extra words the search also matches (setting names, descriptions).
|
||||
final String keywords;
|
||||
|
||||
/// Whether this section reads the server and loads only when near or searched.
|
||||
final bool lazy;
|
||||
|
||||
final WidgetBuilder builder;
|
||||
|
||||
/// Whether every word of [query] appears in the title or keywords, ignoring
|
||||
/// case. An empty query matches every section.
|
||||
bool matches(String query) {
|
||||
final words = query
|
||||
.trim()
|
||||
.toLowerCase()
|
||||
.split(RegExp(r'\s+'))
|
||||
.where((word) => word.isNotEmpty);
|
||||
if (words.isEmpty) return true;
|
||||
final haystack = '$title $keywords'.toLowerCase();
|
||||
return words.every(haystack.contains);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
import 'package:flutter/foundation.dart';
|
||||
|
||||
/// One server-backed Settings value.
|
||||
///
|
||||
/// It loads once when its section mounts, never starts a second load while one
|
||||
/// is in flight, and keeps the last good value when a refresh fails, so a
|
||||
/// flaky server shows stale data with a Retry rather than an empty section.
|
||||
class ServerLoad<T> extends ChangeNotifier {
|
||||
ServerLoad(this._fetch);
|
||||
|
||||
final Future<T> Function() _fetch;
|
||||
T? _value;
|
||||
bool _hasValue = false;
|
||||
Object? _error;
|
||||
bool _loading = false;
|
||||
Future<void>? _inFlight;
|
||||
bool _disposed = false;
|
||||
|
||||
/// The last value the server returned, or null before the first success.
|
||||
T? get value => _value;
|
||||
bool get hasValue => _hasValue;
|
||||
|
||||
/// The error from the latest attempt, cleared when a new attempt starts.
|
||||
Object? get error => _error;
|
||||
bool get loading => _loading;
|
||||
|
||||
/// Starts a load unless one is already running; returns that load's future.
|
||||
Future<void> load() {
|
||||
final running = _inFlight;
|
||||
if (running != null) return running;
|
||||
_loading = true;
|
||||
_error = null;
|
||||
_notify();
|
||||
final future = _run();
|
||||
_inFlight = future;
|
||||
return future;
|
||||
}
|
||||
|
||||
/// Retries after a failure or refreshes a cached value.
|
||||
Future<void> refresh() => load();
|
||||
|
||||
Future<void> _run() async {
|
||||
try {
|
||||
final next = await _fetch();
|
||||
if (_disposed) return;
|
||||
_value = next;
|
||||
_hasValue = true;
|
||||
} catch (error) {
|
||||
if (!_disposed) _error = error;
|
||||
} finally {
|
||||
_loading = false;
|
||||
_inFlight = null;
|
||||
_notify();
|
||||
}
|
||||
}
|
||||
|
||||
void _notify() {
|
||||
if (!_disposed) notifyListeners();
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_disposed = true;
|
||||
super.dispose();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,138 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'settings_layout.dart';
|
||||
import 'settings_server_load.dart';
|
||||
import 'settings_theme.dart';
|
||||
|
||||
String _describeDefault(Object error) => '$error';
|
||||
|
||||
/// Shows a [ServerLoad] inside its section: the last value (with any refresh
|
||||
/// error and a Retry beside it), a placeholder while the first load runs, or
|
||||
/// the error with Retry. Other sections are never affected by this one.
|
||||
///
|
||||
/// The view starts the first load when it mounts, which happens only once the
|
||||
/// page reaches its section; a cached value is never refetched by a rebuild.
|
||||
class ServerSettingsView<T> extends StatefulWidget {
|
||||
const ServerSettingsView({
|
||||
super.key,
|
||||
required this.load,
|
||||
required this.builder,
|
||||
this.describe = _describeDefault,
|
||||
this.retryKey,
|
||||
});
|
||||
|
||||
final ServerLoad<T> load;
|
||||
final Widget Function(BuildContext context, T value) builder;
|
||||
|
||||
/// Turns a failure into the line the operator reads.
|
||||
final String Function(Object error) describe;
|
||||
final Key? retryKey;
|
||||
|
||||
@override
|
||||
State<ServerSettingsView<T>> createState() => _ServerSettingsViewState<T>();
|
||||
}
|
||||
|
||||
class _ServerSettingsViewState<T> extends State<ServerSettingsView<T>> {
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_startIfNeeded();
|
||||
}
|
||||
|
||||
@override
|
||||
void didUpdateWidget(ServerSettingsView<T> oldWidget) {
|
||||
super.didUpdateWidget(oldWidget);
|
||||
if (oldWidget.load != widget.load) _startIfNeeded();
|
||||
}
|
||||
|
||||
void _startIfNeeded() {
|
||||
final load = widget.load;
|
||||
if (!load.hasValue && !load.loading && load.error == null) {
|
||||
unawaited(load.load());
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final load = widget.load;
|
||||
return ListenableBuilder(
|
||||
listenable: load,
|
||||
builder: (context, _) => _content(context, load),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _content(BuildContext context, ServerLoad<T> load) {
|
||||
final error = load.error;
|
||||
if (load.hasValue) {
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: <Widget>[
|
||||
widget.builder(context, load.value as T),
|
||||
if (error != null) _error(context, error),
|
||||
],
|
||||
);
|
||||
}
|
||||
if (error != null) return _error(context, error);
|
||||
return const SettingsPlaceholder();
|
||||
}
|
||||
|
||||
Widget _error(BuildContext context, Object error) => Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: <Widget>[
|
||||
Semantics(
|
||||
liveRegion: true,
|
||||
child: Text(
|
||||
widget.describe(error),
|
||||
style: settingsTextStyle(context, error: true),
|
||||
),
|
||||
),
|
||||
Align(
|
||||
alignment: AlignmentDirectional.centerStart,
|
||||
child: TextButton(
|
||||
key: widget.retryKey,
|
||||
onPressed: widget.load.loading ? null : () => widget.load.refresh(),
|
||||
child: const Text('Retry'),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
/// A loading placeholder for a value that has not arrived: two text-height
|
||||
/// bars in the surface colour, sized from the text scale.
|
||||
class SettingsPlaceholder extends StatelessWidget {
|
||||
const SettingsPlaceholder({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = Theme.of(context);
|
||||
final scaler = MediaQuery.textScalerOf(context);
|
||||
final line = scaler.scale(theme.textTheme.bodyMedium?.fontSize ?? 14);
|
||||
final color = theme.colorScheme.surfaceContainerHighest;
|
||||
Widget bar(double widthFactor) => FractionallySizedBox(
|
||||
alignment: AlignmentDirectional.centerStart,
|
||||
widthFactor: widthFactor,
|
||||
child: Container(
|
||||
height: line,
|
||||
decoration: BoxDecoration(
|
||||
color: color,
|
||||
borderRadius: BorderRadius.circular(settingsFieldGap),
|
||||
),
|
||||
),
|
||||
);
|
||||
return Semantics(
|
||||
label: 'Loading',
|
||||
excludeSemantics: true,
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: <Widget>[
|
||||
bar(0.9),
|
||||
const SizedBox(height: settingsTitleGap),
|
||||
bar(0.6),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'settings_group.dart';
|
||||
import 'settings_server_view.dart';
|
||||
|
||||
/// A group-shaped placeholder for a lazy section that has not been reached yet.
|
||||
/// It keeps the section's heading, so the page reads the same before and after
|
||||
/// the section loads.
|
||||
class SettingsSkeleton extends StatelessWidget {
|
||||
const SettingsSkeleton({super.key, required this.title});
|
||||
|
||||
final String title;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => SettingsGroup(
|
||||
title: title,
|
||||
children: const <Widget>[SettingsGroupItem(child: SettingsPlaceholder())],
|
||||
);
|
||||
}
|
||||
@@ -1,170 +0,0 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'settings_topic_store.dart';
|
||||
import '../../core/storage/ordered_local_storage.dart';
|
||||
import '../../ui/motion/surface_visibility.dart';
|
||||
|
||||
enum SettingsTopic {
|
||||
appearance('Appearance'),
|
||||
connection('Connection'),
|
||||
notifications('Notifications'),
|
||||
tools('Tools'),
|
||||
updates('Updates');
|
||||
|
||||
const SettingsTopic(this.label);
|
||||
final String label;
|
||||
}
|
||||
|
||||
/// Topic pages are created on first visit, then retained with their drafts and
|
||||
/// independent scroll positions. Hidden pages do not tick animations.
|
||||
class SettingsTopicTabs extends StatefulWidget {
|
||||
const SettingsTopicTabs({
|
||||
super.key,
|
||||
required this.pages,
|
||||
this.navigationScope,
|
||||
this.selectionStore,
|
||||
});
|
||||
final Map<SettingsTopic, WidgetBuilder> pages;
|
||||
|
||||
/// Null keeps standalone previews independent of application persistence.
|
||||
final String? navigationScope;
|
||||
final SettingsTopicStore? selectionStore;
|
||||
@override
|
||||
State<SettingsTopicTabs> createState() => _SettingsTopicTabsState();
|
||||
}
|
||||
|
||||
class _SettingsTopicTabsState extends State<SettingsTopicTabs>
|
||||
with SingleTickerProviderStateMixin {
|
||||
late final TabController _tabs;
|
||||
SettingsTopic _selected = SettingsTopic.appearance;
|
||||
final Set<SettingsTopic> _visited = {SettingsTopic.appearance};
|
||||
SettingsTopicStore? _store;
|
||||
int _revision = 0;
|
||||
bool _restoring = false;
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_tabs = TabController(length: SettingsTopic.values.length, vsync: this);
|
||||
_tabs.addListener(_changed);
|
||||
_bindStore();
|
||||
}
|
||||
|
||||
@override
|
||||
void didUpdateWidget(SettingsTopicTabs oldWidget) {
|
||||
super.didUpdateWidget(oldWidget);
|
||||
if (oldWidget.navigationScope != widget.navigationScope ||
|
||||
oldWidget.selectionStore != widget.selectionStore) {
|
||||
_bindStore();
|
||||
}
|
||||
}
|
||||
|
||||
void _bindStore() {
|
||||
_store =
|
||||
widget.selectionStore ??
|
||||
(widget.navigationScope == null
|
||||
? null
|
||||
: SharedPreferencesSettingsTopicStore(widget.navigationScope!));
|
||||
final revision = ++_revision;
|
||||
final store = _store;
|
||||
if (store == null) return;
|
||||
unawaited(_restore(store, revision));
|
||||
}
|
||||
|
||||
Future<void> _restore(SettingsTopicStore store, int revision) async {
|
||||
String? saved;
|
||||
try {
|
||||
saved = await _ordered(store, store.load);
|
||||
} catch (_) {
|
||||
return;
|
||||
}
|
||||
if (!mounted || revision != _revision) return;
|
||||
final topic =
|
||||
SettingsTopic.values
|
||||
.where((topic) => topic.name == saved)
|
||||
.firstOrNull ??
|
||||
SettingsTopic.appearance;
|
||||
_restoring = true;
|
||||
_tabs.index = topic.index;
|
||||
_restoring = false;
|
||||
}
|
||||
|
||||
Future<T> _ordered<T>(
|
||||
SettingsTopicStore store,
|
||||
Future<T> Function() operation,
|
||||
) => store is SharedPreferencesSettingsTopicStore
|
||||
? operation()
|
||||
: orderedLocalStorage(store, operation);
|
||||
|
||||
void _persist(SettingsTopicStore store, String topic) {
|
||||
// Register accepted choices synchronously, before a replacement can load.
|
||||
// The production store coordinates all instances by their preference key.
|
||||
unawaited(
|
||||
_ordered(store, () => store.save(topic)).catchError((Object _) {
|
||||
// Navigation continues when the local preference cannot be saved.
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
void _changed() {
|
||||
if (!mounted) return;
|
||||
final next = SettingsTopic.values[_tabs.index];
|
||||
if (next == _selected) return;
|
||||
setState(() {
|
||||
_selected = next;
|
||||
_visited.add(next);
|
||||
});
|
||||
if (_restoring) return;
|
||||
++_revision;
|
||||
final store = _store;
|
||||
if (store != null) _persist(store, next.name);
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_tabs.removeListener(_changed);
|
||||
_tabs.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final tabs = TabBar(
|
||||
controller: _tabs,
|
||||
isScrollable: true,
|
||||
tabAlignment: TabAlignment.start,
|
||||
tabs: [for (final topic in SettingsTopic.values) Tab(text: topic.label)],
|
||||
);
|
||||
return SafeArea(
|
||||
bottom: false,
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
Semantics(container: true, label: 'Settings categories', child: tabs),
|
||||
Expanded(
|
||||
child: IndexedStack(
|
||||
index: _selected.index,
|
||||
children: [
|
||||
for (final topic in SettingsTopic.values)
|
||||
if (_visited.contains(topic))
|
||||
TickerMode(
|
||||
enabled: topic == _selected,
|
||||
child: SurfaceVisibility(
|
||||
shown: true,
|
||||
current: topic == _selected,
|
||||
child: KeyedSubtree(
|
||||
key: ValueKey('settings-topic-${topic.name}'),
|
||||
child: Builder(builder: widget.pages[topic]!),
|
||||
),
|
||||
),
|
||||
)
|
||||
else
|
||||
const SizedBox.shrink(),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,131 +0,0 @@
|
||||
part of 'settings_screen.dart';
|
||||
|
||||
extension _SettingsTopicPages on _SettingsScreenState {
|
||||
Map<SettingsTopic, WidgetBuilder> _topicPages() {
|
||||
final servers = widget.servers;
|
||||
return {
|
||||
SettingsTopic.appearance: (_) => SettingsPageBody(
|
||||
children: [
|
||||
const SettingsScaleSection(),
|
||||
SettingsAnimationSection(
|
||||
controller:
|
||||
widget.animationSpeed ?? AnimationSpeedController.instance,
|
||||
),
|
||||
SettingsFontSection(
|
||||
controller: widget.fonts ?? AppFontController.instance,
|
||||
),
|
||||
SettingsTerminalSection(
|
||||
layout: widget.terminalLayout ?? TerminalLayout.instance,
|
||||
),
|
||||
],
|
||||
),
|
||||
SettingsTopic.connection: (_) => SettingsPageBody(
|
||||
children: [
|
||||
if (servers != null) ...[
|
||||
SavedServersSection(connections: servers),
|
||||
ManagedConnectionSection(
|
||||
client: widget.client,
|
||||
controller: _controller,
|
||||
),
|
||||
] else
|
||||
SettingsConnectionSection(
|
||||
controller: _controller,
|
||||
serverUrlField: _serverUrlField,
|
||||
),
|
||||
if (widget.showSignIn)
|
||||
_single(
|
||||
'Sign in',
|
||||
SettingsSignInSection(
|
||||
endpoint: _endpoint,
|
||||
onChanged: _reconnectAfterSignIn,
|
||||
),
|
||||
),
|
||||
if (widget.showSignIn || kIsWeb)
|
||||
_single(
|
||||
'Sign-in security',
|
||||
SettingsSecuritySection(
|
||||
endpoint: _endpoint,
|
||||
onSignedOut: _reconnectAfterSignIn,
|
||||
),
|
||||
),
|
||||
SettingsWorkspaceSection(
|
||||
controller: _controller,
|
||||
workspaceField: _workspaceField,
|
||||
),
|
||||
],
|
||||
),
|
||||
SettingsTopic.notifications: (_) => SettingsPageBody(
|
||||
children: [
|
||||
if (widget.notifications case final notifications?)
|
||||
SettingsNotificationsSection(controller: notifications),
|
||||
if (widget.deliveryService case final service? when service.supported)
|
||||
SettingsDeviceDeliverySection(
|
||||
bridge: service,
|
||||
controller: widget.deliveryServiceController,
|
||||
requestNotificationPermission: widget.notifications == null
|
||||
? null
|
||||
: () async {
|
||||
await widget.notifications!.requestPermission();
|
||||
},
|
||||
),
|
||||
SettingsNtfySection(
|
||||
gateway: widget.client,
|
||||
connected:
|
||||
widget.client.state.kind == transport.ConnectionKind.connected,
|
||||
),
|
||||
],
|
||||
),
|
||||
SettingsTopic.tools: (_) => SettingsPageBody(
|
||||
children: [
|
||||
_single(
|
||||
'Data management',
|
||||
SettingsStorageSection(gateway: widget.client),
|
||||
),
|
||||
_single('Server', SettingsHealthSection(gateway: widget.client)),
|
||||
SettingsGroup(
|
||||
title: 'Help',
|
||||
leadingRows: true,
|
||||
children: const [
|
||||
SettingsKeyboardShortcutsSection(),
|
||||
SettingsWalkthroughSection(),
|
||||
],
|
||||
),
|
||||
if (widget.onOpenSchedules case final open?)
|
||||
SettingsGroup(
|
||||
title: 'Library',
|
||||
leadingRows: true,
|
||||
children: [SettingsSchedulesSection(onOpen: open)],
|
||||
),
|
||||
],
|
||||
),
|
||||
SettingsTopic.updates: (_) => SettingsPageBody(
|
||||
children: [
|
||||
if (widget.showAndroidDownload)
|
||||
_single('Android app', const SettingsAndroidDownloadSection()),
|
||||
if (widget.showSignIn && appUpdatesSupported)
|
||||
_single(
|
||||
'App updates',
|
||||
SettingsUpdatesSection(
|
||||
endpoint: _endpoint,
|
||||
servers: widget.servers,
|
||||
),
|
||||
),
|
||||
if (!widget.showAndroidDownload &&
|
||||
!(widget.showSignIn && appUpdatesSupported))
|
||||
_single(
|
||||
'App updates',
|
||||
const Text(
|
||||
'This installation is updated by its server administrator.',
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
};
|
||||
}
|
||||
|
||||
/// A group holding one free-form block (a form, a status with buttons).
|
||||
Widget _single(String title, Widget child) => SettingsGroup(
|
||||
title: title,
|
||||
children: <Widget>[SettingsGroupItem(child: child)],
|
||||
);
|
||||
}
|
||||
@@ -1,37 +0,0 @@
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
import '../../core/servers/server_scope.dart';
|
||||
import '../../core/storage/ordered_local_storage.dart';
|
||||
|
||||
const settingsTopicKey = 'pipelines.next.settingsTopic.v1';
|
||||
|
||||
abstract interface class SettingsTopicStore {
|
||||
Future<String?> load();
|
||||
Future<void> save(String topic);
|
||||
}
|
||||
|
||||
/// Stores only the selected category, never unsaved fields or popup state.
|
||||
class SharedPreferencesSettingsTopicStore implements SettingsTopicStore {
|
||||
const SharedPreferencesSettingsTopicStore(this.scope);
|
||||
final String scope;
|
||||
String get key => scopedServerKey(settingsTopicKey, scope);
|
||||
|
||||
@override
|
||||
Future<String?> load() => orderedLocalStorage(key, () async {
|
||||
try {
|
||||
return (await SharedPreferences.getInstance()).getString(key);
|
||||
} catch (_) {
|
||||
return null;
|
||||
}
|
||||
});
|
||||
|
||||
@override
|
||||
Future<void> save(String topic) => orderedLocalStorage(key, () async {
|
||||
try {
|
||||
final preferences = await SharedPreferences.getInstance();
|
||||
await preferences.setString(key, topic);
|
||||
} catch (_) {
|
||||
// The mounted category remains usable when local storage is unavailable.
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../walkthrough/first_run_walkthrough.dart';
|
||||
import 'settings_keys.dart';
|
||||
import 'settings_row.dart';
|
||||
|
||||
/// Reopens the first-run walkthrough. It only shows the walkthrough; it never
|
||||
/// changes the device's seen record.
|
||||
class SettingsWalkthroughSection extends StatelessWidget {
|
||||
const SettingsWalkthroughSection({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => SettingsRow(
|
||||
key: SettingsKeys.walkthrough,
|
||||
leading: const Icon(Icons.school_outlined),
|
||||
title: const Text('Show the walkthrough'),
|
||||
subtitle: const Text(
|
||||
'Four short steps: connect, set up an agent, run, chat.',
|
||||
),
|
||||
chevron: true,
|
||||
onTap: () => showFirstRunWalkthrough(context),
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user