Files
pipelines/app/lib/features/settings/managed_connection_section.dart
T

63 lines
2.1 KiB
Dart
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import 'dart:async';
import 'package:flutter/cupertino.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import '../../core/transport/pipelines_client.dart';
import '../../ui/adaptive/host.dart';
import 'settings_controller.dart';
import 'settings_sections.dart';
import 'settings_trust_warning.dart';
/// Status follows the actual attempted address, not just the preferred URL.
class ManagedConnectionSection extends StatelessWidget {
const ManagedConnectionSection({
super.key,
required this.client,
required this.controller,
});
final PipelinesClient client;
final SettingsController controller;
Widget _action(BuildContext context, String text, VoidCallback? press) =>
usesCupertinoHost(context)
? CupertinoButton(onPressed: press, child: Text(text))
: TextButton(onPressed: press, child: Text(text));
@override
Widget build(BuildContext context) => Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
SelectableText('Current address: ${client.endpoint ?? 'Not connected'}'),
const SizedBox(height: 8),
const Text(
'Reconnect tries the preferred address first. A dropped or '
'unreachable connection tries this server’s backup addresses automatically.',
),
if (kIsWeb)
const Text(
'In a browser, the connection stays on this page’s '
'origin. Use a saved server to open its page; native apps use automatic address fallback.',
),
Wrap(
spacing: 8,
children: [
_action(
context,
'Reconnect',
client.endpoints.isEmpty
? null
: () => unawaited(client.connectAny(client.endpoints)),
),
_action(context, 'Disconnect', () => unawaited(client.disconnect())),
],
),
SettingsStatusCard(controller: controller),
const SizedBox(height: 12),
const SettingsTrustWarning(),
if (controller.protocolWarning case final warning?) Text(warning),
],
);
}