First run: empty states with a next step, harness setup instead of errors
- One shared EmptyState (icon on a tonal disc, title, one line, primary action) that follows the design tokens; used by Runs (Start your first run), Pipelines (Browse templates), Schedules and the chat list (Start a chat). - Chat on a server without an agent harness showed "Bad state: No saved machine is connected.": the federated list now keeps the server's own refusal, treats an omitted empty list as no chats, and the list shows a "Set up an agent" state with the harness setup command and Refresh. New chat shows the same step instead of a form that can only be refused. - A run that fails because no harness CLI exists names the setup command beside the raw reason; error advice gains a noHarness kind. - Templates opened before the app connected stayed on "Not connected"; it now reads again when the connection arrives. The Pipelines empty state links to Templates, which had no entry point in the UI. - The first-launch walkthrough waits briefly for the connection, so a connected web app is no longer told to connect; the empty-server check treats omitted lists and no chat harness as empty. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,143 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../theme/app_design_tokens.dart';
|
||||
|
||||
/// One button of an [EmptyState]: a label, an optional icon and its action.
|
||||
typedef EmptyStateAction = ({
|
||||
String label,
|
||||
IconData? icon,
|
||||
VoidCallback onPressed,
|
||||
});
|
||||
|
||||
/// Builds an [EmptyStateAction]; a named constructor reads better at call
|
||||
/// sites than a record literal.
|
||||
EmptyStateAction emptyStateAction(
|
||||
String label,
|
||||
VoidCallback onPressed, {
|
||||
IconData? icon,
|
||||
}) => (label: label, icon: icon, onPressed: onPressed);
|
||||
|
||||
/// What a list shows when it has nothing yet: never an error, always a next
|
||||
/// step. One look on every screen: a large icon on a tonal disc, a short
|
||||
/// title, one muted line of explanation and up to two actions (the primary
|
||||
/// one filled). [child] adds content under the message, such as a command to
|
||||
/// copy. The whole state scrolls in a short pane instead of overflowing.
|
||||
///
|
||||
/// Shapes follow the active design: the disc takes the design's corner
|
||||
/// radius (square under Terminal, round under Classic and Paper).
|
||||
class EmptyState extends StatelessWidget {
|
||||
const EmptyState({
|
||||
super.key,
|
||||
required this.icon,
|
||||
required this.title,
|
||||
this.message,
|
||||
this.action,
|
||||
this.secondaryAction,
|
||||
this.child,
|
||||
this.dense = false,
|
||||
});
|
||||
|
||||
final IconData icon;
|
||||
final String title;
|
||||
final String? message;
|
||||
final EmptyStateAction? action;
|
||||
final EmptyStateAction? secondaryAction;
|
||||
final Widget? child;
|
||||
|
||||
/// A smaller icon and tighter spacing, for narrow list panes.
|
||||
final bool dense;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = Theme.of(context);
|
||||
final scheme = theme.colorScheme;
|
||||
final tokens = AppDesignTokens.of(context);
|
||||
final disc = dense ? 56.0 : 72.0;
|
||||
final primary = action;
|
||||
final secondary = secondaryAction;
|
||||
return Center(
|
||||
child: SingleChildScrollView(
|
||||
padding: const EdgeInsets.all(24),
|
||||
child: ConstrainedBox(
|
||||
constraints: const BoxConstraints(maxWidth: 420),
|
||||
child: Semantics(
|
||||
container: true,
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
DecoratedBox(
|
||||
decoration: BoxDecoration(
|
||||
color: scheme.secondaryContainer,
|
||||
borderRadius: tokens.corners(
|
||||
BorderRadius.circular(disc / 2),
|
||||
),
|
||||
),
|
||||
child: SizedBox.square(
|
||||
dimension: disc,
|
||||
child: Icon(
|
||||
icon,
|
||||
size: disc / 2,
|
||||
color: scheme.onSecondaryContainer,
|
||||
),
|
||||
),
|
||||
),
|
||||
SizedBox(height: dense ? 12 : 16),
|
||||
Text(
|
||||
title,
|
||||
textAlign: TextAlign.center,
|
||||
style: theme.textTheme.titleMedium,
|
||||
),
|
||||
if (message case final message?) ...[
|
||||
const SizedBox(height: 6),
|
||||
Text(
|
||||
message,
|
||||
textAlign: TextAlign.center,
|
||||
style: theme.textTheme.bodyMedium?.copyWith(
|
||||
color: scheme.onSurfaceVariant,
|
||||
),
|
||||
),
|
||||
],
|
||||
if (child case final child?) ...[
|
||||
const SizedBox(height: 16),
|
||||
child,
|
||||
],
|
||||
if (primary != null || secondary != null) ...[
|
||||
SizedBox(height: dense ? 16 : 20),
|
||||
Wrap(
|
||||
alignment: WrapAlignment.center,
|
||||
spacing: 8,
|
||||
runSpacing: 8,
|
||||
children: [
|
||||
if (primary != null)
|
||||
primary.icon == null
|
||||
? FilledButton(
|
||||
onPressed: primary.onPressed,
|
||||
child: Text(primary.label),
|
||||
)
|
||||
: FilledButton.icon(
|
||||
onPressed: primary.onPressed,
|
||||
icon: Icon(primary.icon),
|
||||
label: Text(primary.label),
|
||||
),
|
||||
if (secondary != null)
|
||||
secondary.icon == null
|
||||
? TextButton(
|
||||
onPressed: secondary.onPressed,
|
||||
child: Text(secondary.label),
|
||||
)
|
||||
: TextButton.icon(
|
||||
onPressed: secondary.onPressed,
|
||||
icon: Icon(secondary.icon),
|
||||
label: Text(secondary.label),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user