// 平板版演示截图生成:把整个应用外壳在 1280×800(平板横屏基准)下渲染为 PNG。 // 运行方式:flutter test --update-goldens test\tablet_screenshots_test.dart // 输出:demo/tablet-*.png import 'package:flutter/material.dart' hide Action; import 'package:flutter_test/flutter_test.dart'; import 'package:sequence_diagram/model/models.dart'; import 'package:sequence_diagram/state/app_controller.dart'; import 'package:sequence_diagram/theme/tokens.dart'; import 'package:sequence_diagram/ui/app_shell.dart'; import 'helpers.dart'; void main() { testWidgets('generate tablet demo screenshots', (WidgetTester tester) async { await tester.runAsync(() => loadZhFonts()); await tester.runAsync(() => loadMaterialIcons()); tester.view.physicalSize = const Size(1280, 800); tester.view.devicePixelRatio = 1.0; addTearDown(tester.view.reset); final AppController c = AppController(project: demoTiming()); addTearDown(c.dispose); Widget shell(Tokens t) => RepaintBoundary( key: const ValueKey('shot'), child: MaterialApp( theme: buildTheme(t), debugShowCheckedModeBanner: false, home: AppShell(controller: c), ), ); Future shot(String path) async { await tester.pump(); await expectLater(find.byKey(const ValueKey('shot')), matchesGoldenFile(path)); } await tester.pumpWidget(shell(Tokens.light)); await shot('../demo/tablet-bar-light.png'); // 展开左右侧栏(浮层)并钉住,展示停靠布局。 // 注意:不能用 find.byIcon(Icons.chevron_right)——画布右下角的预览卡里 // 也有同类图标且更早出现在组件树中,会误触「切换视图」;改为按坐标点贴边轨道。 await tester.tapAt(const Offset(10, 300)); await tester.pump(); if (tester.any(find.byIcon(Icons.push_pin_outlined))) { await tester.tap(find.byIcon(Icons.push_pin_outlined).first); await tester.pump(); } await tester.tapAt(const Offset(1270, 300)); await tester.pump(); if (tester.any(find.byIcon(Icons.push_pin_outlined))) { await tester.tap(find.byIcon(Icons.push_pin_outlined).first); await tester.pump(); } await shot('../demo/tablet-bar-light-panels.png'); // 圆周视图(浅色,含停靠侧栏)。 c.setViewMode(ViewMode.circular); await shot('../demo/tablet-circular-light.png'); // 流程图视图(浅色):由时序图自动生成(泳道 = 轨道,只读)。 c.setViewMode(ViewMode.flow); await shot('../demo/tablet-flow-light.png'); // 流程图导出菜单:SVG / PNG 之外额外提供 drawio 入口(仅流程图)。 await tester.tap(find.text('导出')); await tester.pumpAndSettle(); await shot('../demo/tablet-flow-export-menu-light.png'); await tester.tapAt(const Offset(5, 5)); await tester.pumpAndSettle(); // 选中动作:右侧属性面板进入只读态(滑块 / 依赖编辑置灰)。 c.select('A2'); await shot('../demo/tablet-flow-selected-light.png'); c.select(null); // 深色主题:条形、圆周与流程图。 // 注意:MaterialApp 的主题切换带 200ms 过渡动画,必须等动画结束再截图, // 否则截到的是过渡起点(仍然是浅色)。 c.toggleTheme(); await tester.pumpWidget(shell(Tokens.dark)); await tester.pump(const Duration(milliseconds: 400)); c.setViewMode(ViewMode.bar); await shot('../demo/tablet-bar-dark.png'); c.setViewMode(ViewMode.circular); await shot('../demo/tablet-circular-dark.png'); c.setViewMode(ViewMode.flow); await shot('../demo/tablet-flow-dark.png'); // ---- 1.3.4 泳道加宽(多槽位)演示(浅色)---- // L1 加宽为 2 槽,并把「定位夹紧」放到槽 2;三种视图各出一张对照图。 c.toggleTheme(); await tester.pumpWidget(shell(Tokens.light)); await tester.pump(const Duration(milliseconds: 400)); c.setLaneSlots(0, 2); c.moveActionTo('A2', 0, 1); c.select(null); c.setViewMode(ViewMode.bar); await shot('../demo/tablet-bar-slots-light.png'); c.setViewMode(ViewMode.circular); await shot('../demo/tablet-circular-slots-light.png'); c.setViewMode(ViewMode.flow); await shot('../demo/tablet-flow-slots-light.png'); // ---- 拥挤场景复核:单泳道 5 槽 + 10 个动作(标题持续换行、灰字不被压住)---- final Project base = demoTiming(); final List many = [...base.actions]; for (int i = 0; i < 8; i++) { many.add(Action( id: 'X$i', name: '动作 ${i + 6}', stationId: 'ST1', driver: '气缸 Y${i + 1}', startAngle: 5.0 + i * 12.0, durationAngle: 8, layer: 0, row: i % 5, color: kActionPalette[i % kActionPalette.length], )); } c.loadProject(base.copyWith( actions: many, laneSlots: {0: 5}, autoSaveEnabled: false, )); c.select(null); c.setViewMode(ViewMode.bar); await shot('../demo/tablet-bar-crowded-light.png'); }); }