|
| 1 | +// Copyright 2025 The Flutter Authors |
| 2 | +// Use of this source code is governed by a BSD-style license that can be |
| 3 | +// found in the LICENSE file or at https://developers.google.com/open-source/licenses/bsd. |
| 4 | + |
| 5 | +import 'package:devtools_app_shared/service.dart'; |
| 6 | +import 'package:devtools_app_shared/ui.dart'; |
| 7 | +import 'package:flutter/material.dart'; |
| 8 | + |
| 9 | +import '../../shared/globals.dart'; |
| 10 | +import '../../shared/ui/common_widgets.dart'; |
| 11 | + |
| 12 | +/// An overlay to show when we are not connected to DTD based on the |
| 13 | +/// [DTDConnectionState] classes. |
| 14 | +class NotConnectedOverlay extends StatefulWidget { |
| 15 | + const NotConnectedOverlay(this.connectionState, {super.key}); |
| 16 | + |
| 17 | + final DTDConnectionState connectionState; |
| 18 | + |
| 19 | + @override |
| 20 | + State<NotConnectedOverlay> createState() => _NotConnectedOverlayState(); |
| 21 | +} |
| 22 | + |
| 23 | +class _NotConnectedOverlayState extends State<NotConnectedOverlay> { |
| 24 | + @override |
| 25 | + Widget build(BuildContext context) { |
| 26 | + final connectionState = widget.connectionState; |
| 27 | + final theme = Theme.of(context); |
| 28 | + |
| 29 | + final showSpinner = connectionState is! ConnectionFailedDTDState; |
| 30 | + final showReconnectButton = connectionState is ConnectionFailedDTDState; |
| 31 | + final stateLabel = switch (connectionState) { |
| 32 | + NotConnectedDTDState() => 'Waiting to connect...', |
| 33 | + ConnectingDTDState() => 'Connecting...', |
| 34 | + WaitingToRetryDTDState(seconds: final seconds) => |
| 35 | + 'Reconnecting in $seconds...', |
| 36 | + ConnectionFailedDTDState() => 'Connection Failed', |
| 37 | + // We should never present this widget when connected, but provide a label |
| 38 | + // for debugging if it happens. |
| 39 | + ConnectedDTDState() => 'Connected', |
| 40 | + }; |
| 41 | + |
| 42 | + return DevToolsOverlay( |
| 43 | + fullScreen: true, |
| 44 | + content: Column( |
| 45 | + mainAxisAlignment: MainAxisAlignment.center, |
| 46 | + children: [ |
| 47 | + if (showSpinner) ...const [ |
| 48 | + CircularProgressIndicator(), |
| 49 | + SizedBox(height: defaultSpacing), |
| 50 | + ], |
| 51 | + Text(stateLabel, style: theme.textTheme.headlineMedium), |
| 52 | + if (showReconnectButton) |
| 53 | + ElevatedButton( |
| 54 | + onPressed: () => dtdManager.reconnect(), |
| 55 | + child: const Text('Retry'), |
| 56 | + ), |
| 57 | + ], |
| 58 | + ), |
| 59 | + ); |
| 60 | + } |
| 61 | +} |
0 commit comments