3933ff980c
Keep the Material settings implementation while preserving public Cupertino parameters for later cleanup. Narrow settings tests to the Material-only behavior.
174 lines
6.0 KiB
Dart
174 lines
6.0 KiB
Dart
import 'dart:async';
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'settings_controller.dart';
|
|
import 'settings_controls.dart';
|
|
import 'settings_copy.dart';
|
|
import 'settings_group.dart';
|
|
import 'settings_keys.dart';
|
|
import 'settings_layout.dart';
|
|
import 'settings_status_row.dart';
|
|
import 'settings_trust_warning.dart';
|
|
|
|
export 'settings_status_row.dart';
|
|
|
|
/// Connection controls for a single endpoint: the editable URL with Connect /
|
|
/// Disconnect, the connection's status row and the trusted-network warning as
|
|
/// the group's footer. Every action goes through the shared client the
|
|
/// controller was given; nothing here opens a second connection.
|
|
class SettingsConnectionSection extends StatelessWidget {
|
|
const SettingsConnectionSection({
|
|
super.key,
|
|
required this.controller,
|
|
required this.serverUrlField,
|
|
});
|
|
|
|
final SettingsController controller;
|
|
final TextEditingController serverUrlField;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final errors = <String>[
|
|
if (controller.endpointSaveError.isNotEmpty) controller.endpointSaveError,
|
|
if (controller.actionError.isNotEmpty) controller.actionError,
|
|
];
|
|
return SettingsGroup(
|
|
title: 'Connection',
|
|
footer: settingsConnectionFooter(controller),
|
|
children: <Widget>[
|
|
SettingsGroupItem(
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
|
children: <Widget>[
|
|
SettingsTextField(
|
|
controller: serverUrlField,
|
|
key: SettingsKeys.serverUrl,
|
|
label: 'Server URL',
|
|
placeholder: serverUrlPlaceholder,
|
|
helper: serverUrlHelper,
|
|
error: controller.urlError,
|
|
onChanged: controller.updateServerUrl,
|
|
maxLines: 2,
|
|
),
|
|
const SizedBox(height: settingsTitleGap),
|
|
SettingsActions(
|
|
primaryLabel: controller.primaryActionLabel,
|
|
secondaryLabel: controller.secondaryActionLabel,
|
|
primaryKey: controller.connectionActive
|
|
? SettingsKeys.disconnect
|
|
: SettingsKeys.connect,
|
|
secondaryKey: controller.connectionActive
|
|
? SettingsKeys.connect
|
|
: SettingsKeys.reconnect,
|
|
onPrimary: () => unawaited(
|
|
controller.connectionActive
|
|
? controller.disconnect()
|
|
: controller.connect(),
|
|
),
|
|
onSecondary: () => unawaited(
|
|
controller.connectionActive
|
|
? controller.connect()
|
|
: controller.reconnect(),
|
|
),
|
|
),
|
|
for (final error in errors) ...<Widget>[
|
|
const SizedBox(height: settingsFieldGap),
|
|
Text(error, style: settingsTextStyle(context, error: true)),
|
|
],
|
|
],
|
|
),
|
|
),
|
|
SettingsStatusRow(controller: controller),
|
|
],
|
|
);
|
|
}
|
|
}
|
|
|
|
/// The Connection group's footer: the trust warning, then a protocol
|
|
/// mismatch when the server reports one.
|
|
Widget settingsConnectionFooter(SettingsController controller) => Column(
|
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
|
children: <Widget>[
|
|
const SettingsTrustWarning(),
|
|
if (controller.protocolWarning case final warning?)
|
|
Builder(
|
|
// A live region announces a mismatch the operator did not ask to
|
|
// reveal.
|
|
builder: (context) => Padding(
|
|
padding: const EdgeInsets.only(top: settingsTitleGap),
|
|
child: Semantics(
|
|
liveRegion: true,
|
|
child: Text(
|
|
warning,
|
|
style: TextStyle(color: settingsErrorColor(context)),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
],
|
|
);
|
|
|
|
/// Workspace controls. The path is resolved by the execution server, and the
|
|
/// helper says so explicitly; an empty saved value is named "(none)". Save is
|
|
/// a tonal button while it is unavailable.
|
|
class SettingsWorkspaceSection extends StatelessWidget {
|
|
const SettingsWorkspaceSection({
|
|
super.key,
|
|
required this.controller,
|
|
required this.workspaceField,
|
|
});
|
|
|
|
final SettingsController controller;
|
|
final TextEditingController workspaceField;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final saveError = controller.workspaceSaveError;
|
|
final canSave = canSaveWorkspace(controller.workspaceDraft);
|
|
final save = canSave ? () => unawaited(controller.saveWorkspace()) : null;
|
|
return SettingsGroup(
|
|
title: 'Workspace',
|
|
children: <Widget>[
|
|
SettingsGroupItem(
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
|
children: <Widget>[
|
|
SettingsTextField(
|
|
controller: workspaceField,
|
|
key: SettingsKeys.workspace,
|
|
label: 'Workspace path (on the server)',
|
|
placeholder: workspacePlaceholder,
|
|
helper: workspaceHelper,
|
|
error: controller.workspaceError,
|
|
onChanged: controller.updateWorkspace,
|
|
),
|
|
const SizedBox(height: settingsTitleGap),
|
|
Wrap(
|
|
spacing: settingsControlGap,
|
|
runSpacing: settingsFieldGap,
|
|
crossAxisAlignment: WrapCrossAlignment.center,
|
|
children: <Widget>[
|
|
FilledButton.tonal(
|
|
key: SettingsKeys.saveWorkspace,
|
|
onPressed: save,
|
|
child: const Text('Save workspace'),
|
|
),
|
|
Text(
|
|
savedWorkspaceLine(controller.savedWorkspace),
|
|
style: settingsTextStyle(context, secondary: true),
|
|
),
|
|
],
|
|
),
|
|
if (saveError.isNotEmpty) ...<Widget>[
|
|
const SizedBox(height: settingsFieldGap),
|
|
Text(saveError, style: settingsTextStyle(context, error: true)),
|
|
],
|
|
],
|
|
),
|
|
),
|
|
],
|
|
);
|
|
}
|
|
}
|