Preview quick switch styles with the real local workspace

This commit is contained in:
2026-11-07 19:40:57 +00:00
parent 9a252b67af
commit 53a9cc78a3
7 changed files with 441 additions and 11 deletions
@@ -0,0 +1,174 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import '../../ui/motion/quick_switch_animation.dart';
import '../chat/workspace/chat_workspace.dart';
import 'settings_theme.dart';
/// The real workspace renderer, with local miniature chats. Previewing never
/// opens an operator chat, changes a saved pane layout or contacts the server.
class QuickSwitchPreview extends StatefulWidget {
const QuickSwitchPreview({super.key, required this.animation});
final QuickSwitchAnimation animation;
@override
State<QuickSwitchPreview> createState() => _QuickSwitchPreviewState();
}
class _QuickSwitchPreviewState extends State<QuickSwitchPreview> {
late final ChatWorkspaceController _panes;
@override
void initState() {
super.initState();
_panes = ChatWorkspaceController()..open('First chat');
_panes.splitActive('Second chat', ChatSplitAxis.horizontal);
_schedulePreview();
}
@override
void didUpdateWidget(QuickSwitchPreview oldWidget) {
super.didUpdateWidget(oldWidget);
if (oldWidget.animation != widget.animation) _schedulePreview();
}
void _schedulePreview() {
WidgetsBinding.instance.addPostFrameCallback((_) {
if (mounted && !MediaQuery.disableAnimationsOf(context)) _replay();
});
}
void _replay() {
final next = _panes.panes.firstWhere((p) => p.id != _panes.activePaneId);
_panes.activate(next.id);
}
@override
void dispose() {
_panes.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
final reduced = MediaQuery.disableAnimationsOf(context);
final cupertino = usesCupertinoControls(context);
return Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Wrap(
alignment: WrapAlignment.spaceBetween,
crossAxisAlignment: WrapCrossAlignment.center,
children: [
Text('Preview', style: settingsTextStyle(context, title: true)),
cupertino
? CupertinoButton(
onPressed: reduced ? null : _replay,
child: const Text('Replay animation'),
)
: TextButton.icon(
onPressed: reduced ? null : _replay,
icon: const Icon(Icons.replay),
label: const Text('Replay animation'),
),
],
),
Center(
child: ConstrainedBox(
constraints: const BoxConstraints(maxWidth: 420),
child: AspectRatio(
aspectRatio: 1.6,
child: Semantics(
identifier: 'quick-switch-preview',
label: '${widget.animation.label} animation preview',
image: true,
child: ExcludeSemantics(
child: IgnorePointer(
child: ClipRRect(
borderRadius: BorderRadius.circular(12),
child: ChatWorkspace(
controller: _panes,
animationStyle: widget.animation,
shortcutsEnabled: false,
singlePane: true,
mobilePeeks: true,
paneBuilder: (context, pane, active) => _PreviewChat(
title: pane.sessionId,
alternate: pane.sessionId == 'Second chat',
),
),
),
),
),
),
),
),
),
if (reduced)
const Padding(
padding: EdgeInsets.only(top: 8),
child: Text('Reduced motion is enabled. Preview stays still.'),
),
],
);
}
}
class _PreviewChat extends StatelessWidget {
const _PreviewChat({required this.title, required this.alternate});
final String title;
final bool alternate;
@override
Widget build(BuildContext context) {
final cupertino = usesCupertinoControls(context);
final color = cupertino
? (alternate ? CupertinoColors.systemTeal : CupertinoColors.systemBlue)
.resolveFrom(context)
: (alternate
? Theme.of(context).colorScheme.tertiary
: Theme.of(context).colorScheme.primary);
final background = cupertino
? CupertinoColors.secondarySystemGroupedBackground.resolveFrom(context)
: Theme.of(context).colorScheme.surfaceContainerHigh;
return DecoratedBox(
decoration: BoxDecoration(
color: background,
border: Border.all(color: color.withValues(alpha: .5)),
borderRadius: BorderRadius.circular(12),
),
child: LayoutBuilder(
builder: (context, constraints) => SingleChildScrollView(
child: Padding(
padding: const EdgeInsets.all(12),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(title, style: settingsTextStyle(context, title: true)),
if (constraints.maxHeight > 80) ...[
const SizedBox(height: 12),
for (final width in [0.65, 0.85, 0.5])
Padding(
padding: const EdgeInsets.only(bottom: 8),
child: FractionallySizedBox(
widthFactor: width,
child: SizedBox(
height: 8,
child: ColoredBox(
color: color.withValues(alpha: .18),
),
),
),
),
Text(
'Draft a reply…',
style: settingsTextStyle(context, secondary: true),
),
],
],
),
),
),
),
);
}
}
@@ -3,6 +3,7 @@ import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import '../../ui/motion/quick_switch_animation.dart';
import 'settings_theme.dart';
import 'quick_switch_preview.dart';
class SettingsQuickSwitchControl extends StatelessWidget {
const SettingsQuickSwitchControl({super.key, required this.controller});
@@ -68,6 +69,8 @@ class SettingsQuickSwitchControl extends StatelessWidget {
},
),
Text(controller.value.description),
const SizedBox(height: 8),
QuickSwitchPreview(animation: controller.value),
if (controller.saveFailed)
Text(
'Could not save; applies until reload.',
@@ -187,7 +187,7 @@ void main() {
selected,
reason: '$destination: $rowKey after opening $key',
);
// Every list uses the shared row and its highlight.
// Every list retains shared row semantics; features may supply their own fill.
final context = tester.element(row);
expect(tester.widget<AppListRow>(row).selected, selected);
final surface = find.descendant(
@@ -199,10 +199,11 @@ void main() {
? tester.widget<ColoredBox>(surface).color
: tester.widget<Material>(surface).color,
selected
? AppListRow.selectedColor(
context,
cupertino: cupertino,
)
? tester.widget<AppListRow>(row).selectedFill ??
AppListRow.selectedColor(
context,
cupertino: cupertino,
)
: const Color(0x00000000),
);
}
@@ -0,0 +1,61 @@
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/features/settings/quick_switch_preview.dart';
import 'package:pipelines_app/features/chat/workspace/chat_workspace.dart';
import 'package:pipelines_app/ui/motion/quick_switch_animation.dart';
Widget _host(QuickSwitchAnimation style, {bool reduced = false}) => MaterialApp(
home: Scaffold(
body: MediaQuery(
data: MediaQueryData(disableAnimations: reduced),
child: SingleChildScrollView(child: QuickSwitchPreview(animation: style)),
),
),
);
void main() {
testWidgets('preview replays the real local workspace with chosen style', (
tester,
) async {
await tester.pumpWidget(_host(QuickSwitchAnimation.cardStack));
await tester.pumpAndSettle();
final workspace = tester.widget<ChatWorkspace>(find.byType(ChatWorkspace));
expect(workspace.animationStyle, QuickSwitchAnimation.cardStack);
expect(workspace.controller.paneCount, 2);
final active = workspace.controller.activePaneId;
await tester.tap(find.text('Replay animation'));
await tester.pumpAndSettle();
expect(workspace.controller.activePaneId, isNot(active));
expect(tester.binding.transientCallbackCount, 0);
await tester.pumpWidget(_host(QuickSwitchAnimation.swap));
await tester.pumpAndSettle();
expect(
tester.widget<ChatWorkspace>(find.byType(ChatWorkspace)).controller,
same(workspace.controller),
);
expect(
tester.widget<ChatWorkspace>(find.byType(ChatWorkspace)).animationStyle,
QuickSwitchAnimation.swap,
);
expect(tester.takeException(), isNull);
});
testWidgets('reduced-motion preview remains still and disables replay', (
tester,
) async {
await tester.pumpWidget(
_host(QuickSwitchAnimation.cardStack, reduced: true),
);
await tester.pumpAndSettle();
expect(
find.text('Reduced motion is enabled. Preview stays still.'),
findsOneWidget,
);
final button = tester.widget<TextButton>(
find.widgetWithText(TextButton, 'Replay animation'),
);
expect(button.onPressed, isNull);
expect(tester.binding.transientCallbackCount, 0);
expect(tester.takeException(), isNull);
});
}
@@ -27,8 +27,14 @@ void main() {
final section = SettingsAnimationSection(controller: controller);
await tester.pumpWidget(
cupertino
? CupertinoApp(home: CupertinoPageScaffold(child: section))
: MaterialApp(home: Scaffold(body: section)),
? CupertinoApp(
home: CupertinoPageScaffold(
child: SingleChildScrollView(child: section),
),
)
: MaterialApp(
home: Scaffold(body: SingleChildScrollView(child: section)),
),
);
if (cupertino) {
final slider = tester.widget<CupertinoSlider>(
@@ -31,8 +31,14 @@ void main() {
);
await tester.pumpWidget(
cupertino
? CupertinoApp(home: CupertinoPageScaffold(child: child))
: MaterialApp(home: Scaffold(body: child)),
? CupertinoApp(
home: CupertinoPageScaffold(
child: SingleChildScrollView(child: child),
),
)
: MaterialApp(
home: Scaffold(body: SingleChildScrollView(child: child)),
),
);
expect(find.text('Quick switch animation'), findsOneWidget);
expect(
@@ -41,7 +47,7 @@ void main() {
);
await tester.tap(find.text('Tape'));
await tester.pumpAndSettle();
await tester.tap(find.text('Card stack').last);
await tester.tap(find.text('Card deck').last);
await tester.pumpAndSettle();
expect(controller.value, QuickSwitchAnimation.cardStack);
expect(store.saved, 'cardStack');
@@ -50,7 +56,7 @@ void main() {
findsOneWidget,
);
store.success = false;
await tester.tap(find.text('Card stack'));
await tester.tap(find.text('Card deck'));
await tester.pumpAndSettle();
await tester.tap(find.text('Swap').last);
await tester.pumpAndSettle();
@@ -0,0 +1,179 @@
{
"size": "560x1000",
"platform": "material",
"theme": "dark",
"params": "chats=4&colors=1&header=1&rich=1",
"steps": [
{
"open": "/settings"
},
{
"shot": "appearance"
},
{
"click": "Tape"
},
{
"shot": "all-animation-options"
},
{
"click": "Card deck"
},
{
"film": "Replay animation",
"name": "card-deck",
"ms": 900,
"frames": 6
},
{
"click": "Card deck"
},
{
"click": "Deck slide"
},
{
"film": "Replay animation",
"name": "deck-slide",
"ms": 900,
"frames": 6
},
{
"click": "Deck slide"
},
{
"click": "Fan"
},
{
"film": "Replay animation",
"name": "fan",
"ms": 900,
"frames": 6
},
{
"click": "Fan"
},
{
"click": "Slide"
},
{
"film": "Replay animation",
"name": "slide",
"ms": 900,
"frames": 6
},
{
"click": "Slide"
},
{
"click": "Push"
},
{
"film": "Replay animation",
"name": "push",
"ms": 900,
"frames": 6
},
{
"click": "Push"
},
{
"click": "Crossfade"
},
{
"film": "Replay animation",
"name": "crossfade",
"ms": 900,
"frames": 6
},
{
"click": "Crossfade"
},
{
"click": "Zoom"
},
{
"film": "Replay animation",
"name": "zoom",
"ms": 900,
"frames": 6
},
{
"click": "Zoom"
},
{
"click": "Flip"
},
{
"film": "Replay animation",
"name": "flip",
"ms": 900,
"frames": 6
},
{
"click": "Flip"
},
{
"click": "Rolodex"
},
{
"film": "Replay animation",
"name": "rolodex",
"ms": 900,
"frames": 6
},
{
"click": "Rolodex"
},
{
"click": "Swap"
},
{
"film": "Replay animation",
"name": "swap",
"ms": 900,
"frames": 6
},
{
"click": "Swap"
},
{
"click": "Tape"
},
{
"film": "Replay animation",
"name": "tape",
"ms": 900,
"frames": 6
},
{
"click": "Connection"
},
{
"shot": "connection"
},
{
"click": "Notifications"
},
{
"shot": "notifications"
},
{
"click": "Tools"
},
{
"shot": "tools"
},
{
"click": "Updates"
},
{
"shot": "updates"
},
{
"click": "Appearance"
},
{
"shot": "appearance"
}
]
}