import 'dart:async'; import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import '../../core/transport/pipelines_client.dart'; import 'settings_controller.dart'; import 'settings_group.dart'; import 'settings_row.dart'; import 'settings_sections.dart'; /// The short line under the managed connection's rows. const String managedConnectionHelp = 'Reconnect tries the preferred address first, then the backups.'; /// The browser-only addition to [managedConnectionHelp]. const String managedConnectionWebHelp = 'In a browser the connection stays on this page’s origin.'; /// The saved-server connection: its state, the address actually attempted and /// Reconnect / Disconnect rows. 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; @override Widget build(BuildContext context) { return SettingsGroup( title: 'Connection', leadingRows: true, footer: Column( crossAxisAlignment: CrossAxisAlignment.stretch, children: [ Text( kIsWeb ? '$managedConnectionHelp $managedConnectionWebHelp' : managedConnectionHelp, ), const SizedBox(height: 12), settingsConnectionFooter(controller), ], ), children: [ SettingsStatusRow(controller: controller), SettingsRow( leading: Icon(Icons.link), title: const Text('Current address'), subtitle: SelectableText('${client.endpoint ?? 'Not connected'}'), ), SettingsRow( action: true, enabled: client.endpoints.isNotEmpty, leading: Icon(Icons.refresh), title: const Text('Reconnect'), onTap: () => unawaited(client.connectAny(client.endpoints)), ), SettingsRow( action: true, leading: Icon(Icons.link_off), title: const Text('Disconnect'), onTap: () => unawaited(client.disconnect()), ), ], ); } }