feat(workspace): 桌面工作区、主题与交互更新,发布 0.1.2
Gitea CI / Check code and tests (push) Successful in 6m37s
Gitea CI / Build Windows x64 app (push) Successful in 3m18s
Gitea CI / Build Android APK (push) Successful in 3m47s
Gitea CI / Audit and package Windows x64 (push) Successful in 1m7s
Gitea CI / Assemble and validate CI artifacts (push) Successful in 50s
Gitea CI / Gitea CI passed (push) Successful in 2s
Gitea Release / Prepare draft Release (push) Successful in 9s
Gitea Release / Upload Android to draft Release (push) Successful in 16s
Gitea Release / Upload Windows to draft Release (push) Successful in 22s
Gitea Release / Verify and publish Release (push) Successful in 14s

This commit was merged in pull request #13.
This commit is contained in:
lingjhf committed 2026-10-08 18:17:12 +00:00
1 parent aa5255d1e4
commit abc1868550
260 files changed
+43964 -5591

No files matched your search

@@ -0,0 +1,80 @@
import 'package:cutdex_ui/icons.dart';
import 'package:cutdex_ui/theme.dart';
import 'package:cutdex_ui/widgets.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('overflow keeps view controls visible and runs hidden commands', (
tester,
) async {
var deleted = 0;
var fitted = 0;
final commands = [
const AppToolbarCommand(
label: 'Undo',
icon: AppIcons.undo,
onPressed: null,
),
AppToolbarCommand(label: 'Redo', icon: AppIcons.redo, onPressed: () {}),
AppToolbarCommand(label: 'Split', icon: AppIcons.cut, onPressed: () {}),
AppToolbarCommand(
label: 'Trim left',
icon: AppIcons.alignLeft,
onPressed: () {},
),
AppToolbarCommand(
label: 'Trim right',
icon: AppIcons.alignRight,
onPressed: () {},
),
AppToolbarCommand(
label: 'Delete',
icon: AppIcons.delete,
onPressed: () => deleted++,
),
];
Widget toolbar(double width) => MaterialApp(
theme: AppTheme.desktopWorkspaceTheme(
AppTheme.forPalette(AppPalette.graphite, Brightness.dark),
),
home: Scaffold(
body: Align(
alignment: Alignment.topLeft,
child: SizedBox(
width: width,
height: 36,
child: AppCommandToolbar(
groups: [commands.take(2).toList(), commands.skip(2).toList()],
trailing: [
AppToolbarCommand(
label: 'Fit',
icon: AppIcons.fitContent,
onPressed: () => fitted++,
),
],
),
),
),
),
);
for (final width in [128.0, 180.0, 200.0, 240.0, 480.0]) {
await tester.pumpWidget(toolbar(width));
expect(tester.takeException(), isNull);
expect(
find.widgetWithIcon(IconButton, AppIcons.fitContent),
findsOneWidget,
);
}
expect(find.byKey(const Key('toolbar-overflow')), findsNothing);
await tester.pumpWidget(toolbar(180));
await tester.tap(find.widgetWithIcon(IconButton, AppIcons.fitContent));
expect(fitted, 1);
await tester.tap(find.byKey(const Key('toolbar-overflow')));
await tester.pumpAndSettle();
await tester.tap(find.text('Delete'));
await tester.pumpAndSettle();
expect(deleted, 1);
expect(tester.takeException(), isNull);
});
}
+153
View File
@@ -0,0 +1,153 @@
import 'dart:ui' as ui;
import 'package:cutdex_ui/cutdex_ui.dart';
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
void main() {
TestWidgetsFlutterBinding.ensureInitialized();
setUpAll(() async {
for (final family in ['PhosphorRegular', 'PhosphorFill']) {
final loader = FontLoader('packages/cutdex_ui/$family')
..addFont(
rootBundle.load('packages/cutdex_ui/assets/fonts/$family.ttf'),
);
await loader.load();
}
});
testWidgets('bundled fonts render distinct glyphs and filled shapes', (
tester,
) async {
final close = await renderIcon(tester, AppIcons.close);
final check = await renderIcon(tester, AppIcons.check);
final star = await renderIcon(tester, AppIcons.star);
final filledStar = await renderIcon(tester, AppIcons.starFilled);
// Missing fonts would render identical fallback boxes for these codepoints.
expect(close, isNot(orderedEquals(check)));
expect(paintedPixels(close), greaterThan(0));
expect(paintedPixels(star), greaterThan(0));
expect(paintedPixels(filledStar), greaterThan(paintedPixels(star)));
});
testWidgets('IconData works in WorkspacePanel and inherits IconTheme', (
tester,
) async {
await tester.pumpWidget(
const MaterialApp(
home: IconTheme(
data: IconThemeData(color: Colors.purple),
child: WorkspacePanel(
title: 'Media',
icon: AppIcons.video,
child: SizedBox(),
),
),
),
);
final icon = find.byIcon(AppIcons.video);
expect(icon, findsOneWidget);
final text = tester.widget<RichText>(
find.descendant(of: icon, matching: find.byType(RichText)),
);
expect(text.text.style!.color, Colors.purple);
expect(text.text.style!.fontFamily, 'packages/cutdex_ui/PhosphorRegular');
expect(tester.takeException(), isNull);
});
testWidgets('RTL mirrors navigation while preserving playback direction', (
tester,
) async {
await tester.pumpWidget(
const Directionality(
textDirection: TextDirection.rtl,
child: Row(children: [Icon(AppIcons.arrowBack), Icon(AppIcons.play)]),
),
);
expect(
find.descendant(
of: find.byIcon(AppIcons.arrowBack),
matching: find.byType(Transform),
),
findsOneWidget,
);
expect(
find.descendant(
of: find.byIcon(AppIcons.play),
matching: find.byType(Transform),
),
findsNothing,
);
});
testWidgets('workspace themes replace implicit Material action icons', (
tester,
) async {
var backPressed = 0;
for (final theme in [AppTheme.penLight, AppTheme.penDark]) {
await tester.pumpWidget(
MaterialApp(
theme: theme,
home: Scaffold(
body: Row(
children: [
BackButton(onPressed: () => backPressed++),
CloseButton(onPressed: () {}),
const DrawerButton(),
const EndDrawerButton(),
],
),
),
),
);
expect(find.byIcon(AppIcons.arrowBack), findsOneWidget);
expect(find.byIcon(AppIcons.close), findsOneWidget);
expect(find.byIcon(AppIcons.menu), findsNWidgets(2));
expect(find.byTooltip('Back'), findsOneWidget);
await tester.tap(find.byIcon(AppIcons.arrowBack));
}
expect(backPressed, 2);
});
}
Future<Uint8List> renderIcon(WidgetTester tester, IconData icon) async {
final key = GlobalKey();
await tester.pumpWidget(
Directionality(
textDirection: TextDirection.ltr,
child: Center(
child: RepaintBoundary(
key: key,
child: SizedBox.square(
dimension: 48,
child: Icon(icon, size: 48, color: Colors.black),
),
),
),
),
);
final boundary =
key.currentContext!.findRenderObject()! as RenderRepaintBoundary;
final pixels = await tester.runAsync(() async {
final image = await boundary.toImage();
try {
final data = await image.toByteData(format: ui.ImageByteFormat.rawRgba);
return Uint8List.fromList(data!.buffer.asUint8List());
} finally {
image.dispose();
}
});
return pixels!;
}
int paintedPixels(Uint8List rgba) {
var result = 0;
for (var index = 3; index < rgba.length; index += 4) {
if (rgba[index] != 0) result++;
}
return result;
}
+290 -1
View File
@@ -1,3 +1,4 @@
import 'package:cutdex_ui/icons.dart';
import 'package:cutdex_ui/theme.dart';
import 'package:cutdex_ui/widgets.dart';
import 'package:flutter/gestures.dart';
@@ -7,6 +8,294 @@ import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
void main() {
for (final dismissal in ['trigger', 'selection', 'outside']) {
testWidgets(
'pointer $dismissal dismissal releases menu trigger highlight',
(tester) async {
late FocusNode triggerFocus;
final states = WidgetStatesController();
addTearDown(states.dispose);
var closed = 0;
await tester.pumpWidget(
MaterialApp(
theme: AppTheme.penDark,
home: Scaffold(
body: Align(
alignment: Alignment.topLeft,
child: AppDropdownMenu(
onClose: () => closed++,
items: [AppMenuItem(label: 'Action', onPressed: () {})],
builder: (_, toggle, focus) {
triggerFocus = focus;
return TextButton(
focusNode: focus,
statesController: states,
onPressed: toggle,
child: const Text('Open'),
);
},
),
),
),
),
);
final mouse = await tester.createGesture(kind: PointerDeviceKind.mouse);
await mouse.addPointer(location: const Offset(400, 400));
Future<void> click(Offset point) async {
await mouse.moveTo(point);
await mouse.down(point);
await mouse.up();
}
await click(tester.getCenter(find.text('Open')));
await tester.pumpAndSettle();
expect(find.text('Action'), findsOneWidget);
switch (dismissal) {
case 'trigger':
await click(tester.getCenter(find.text('Open')));
case 'selection':
await click(tester.getCenter(find.text('Action')));
case 'outside':
await click(const Offset(400, 400));
}
await mouse.moveTo(const Offset(450, 450));
await tester.pumpAndSettle();
expect(find.text('Action'), findsNothing);
expect(closed, 1);
expect(triggerFocus.hasFocus, isFalse);
expect(states.value, isNot(contains(WidgetState.focused)));
expect(states.value, isNot(contains(WidgetState.hovered)));
await mouse.removePointer();
expect(tester.takeException(), isNull);
},
);
}
for (final kind in [PointerDeviceKind.mouse, PointerDeviceKind.touch]) {
testWidgets('dropdown outside $kind click activates buttons and inputs', (
tester,
) async {
var outsideClicks = 0;
var menuActions = 0;
final inputFocus = FocusNode();
addTearDown(inputFocus.dispose);
await tester.pumpWidget(
MaterialApp(
theme: AppTheme.penLight,
home: Scaffold(
body: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
AppDropdownMenu(
items: [
AppMenuItem(
label: 'Menu action',
onPressed: () => menuActions++,
),
],
builder: (_, toggle, focus) => TextButton(
focusNode: focus,
onPressed: toggle,
child: const Text('Open menu'),
),
),
const SizedBox(height: 200),
TextButton(
onPressed: () => outsideClicks++,
child: const Text('Outside button'),
),
SizedBox(width: 240, child: TextField(focusNode: inputFocus)),
],
),
),
),
);
await tester.tap(find.text('Open menu'), kind: kind);
await tester.pumpAndSettle();
expect(find.text('Menu action'), findsOneWidget);
await tester.tap(find.text('Outside button'), kind: kind);
await tester.pumpAndSettle();
expect(find.text('Menu action'), findsNothing);
expect(outsideClicks, 1);
await tester.tap(find.text('Open menu'), kind: kind);
await tester.pumpAndSettle();
await tester.tap(find.byType(TextField), kind: kind);
await tester.pumpAndSettle();
expect(find.text('Menu action'), findsNothing);
expect(inputFocus.hasFocus, isTrue);
expect(menuActions, 0);
expect(tester.takeException(), isNull);
});
testWidgets('dropdowns and selects switch on the first $kind click', (
tester,
) async {
var selected = 0;
var actions = 0;
Widget dropdown(String name) => AppDropdownMenu(
items: [AppMenuItem(label: '$name action', onPressed: () => actions++)],
builder: (_, toggle, focus) =>
TextButton(focusNode: focus, onPressed: toggle, child: Text(name)),
);
await tester.pumpWidget(
MaterialApp(
theme: AppTheme.penDark,
home: Scaffold(
body: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
dropdown('First'),
dropdown('Second'),
SizedBox(
width: 200,
child: AppSelect<int>(
value: selected,
options: const [
AppSelectOption(0, 'Automatic'),
AppSelectOption(1, 'Manual'),
],
onChanged: (next) => selected = next,
label: 'Mode',
emptyLabel: 'No options',
),
),
],
),
),
),
);
await tester.tap(find.text('First'), kind: kind);
await tester.pumpAndSettle();
expect(find.text('First action'), findsOneWidget);
await tester.tap(find.text('Second'), kind: kind);
await tester.pumpAndSettle();
expect(find.text('First action'), findsNothing);
expect(find.text('Second action'), findsOneWidget);
// Clicking the open menu's own trigger still closes it.
await tester.tap(find.text('Second'), kind: kind);
await tester.pumpAndSettle();
expect(find.text('Second action'), findsNothing);
await tester.tap(find.text('First'), kind: kind);
await tester.pumpAndSettle();
await tester.tap(
find.widgetWithText(TextButton, 'Automatic'),
kind: kind,
);
await tester.pumpAndSettle();
expect(find.text('First action'), findsNothing);
expect(find.widgetWithText(MenuItemButton, 'Manual'), findsOneWidget);
await tester.tap(find.text('First'), kind: kind);
await tester.pumpAndSettle();
expect(find.widgetWithText(MenuItemButton, 'Manual'), findsNothing);
expect(find.text('First action'), findsOneWidget);
expect(selected, 0);
await tester.tap(find.text('First action'), kind: kind);
await tester.pumpAndSettle();
expect(actions, 1);
expect(find.text('First action'), findsNothing);
expect(tester.takeException(), isNull);
});
}
testWidgets('Flutter context menu outside click also activates its target', (
tester,
) async {
debugDefaultTargetPlatformOverride = TargetPlatform.windows;
addTearDown(() => debugDefaultTargetPlatformOverride = null);
var outsideClicks = 0;
await tester.pumpWidget(
MaterialApp(
theme: AppTheme.penDark,
home: Scaffold(
body: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
AppContextMenu(
itemsBuilder: (_) => [
AppMenuItem(label: 'Context action', onPressed: () {}),
],
child: const SizedBox(width: 100, height: 100),
),
const SizedBox(height: 200),
TextButton(
onPressed: () => outsideClicks++,
child: const Text('Outside button'),
),
],
),
),
),
);
await tester.tap(
find.byType(AppContextMenu),
kind: PointerDeviceKind.mouse,
buttons: kSecondaryMouseButton,
);
await tester.pumpAndSettle();
expect(find.text('Context action'), findsOneWidget);
await tester.tap(
find.text('Outside button'),
kind: PointerDeviceKind.mouse,
);
await tester.pumpAndSettle();
expect(find.text('Context action'), findsNothing);
expect(outsideClicks, 1);
expect(tester.takeException(), isNull);
debugDefaultTargetPlatformOverride = null;
});
testWidgets('dropdown offsets do not inherit or overwrite expansion state', (
tester,
) async {
final bucket = PageStorageBucket();
const ancestorKey = PageStorageKey('expanded-property');
int? selected;
await tester.pumpWidget(
MaterialApp(
theme: AppTheme.penDark,
home: Scaffold(
body: PageStorage(
bucket: bucket,
child: Builder(
key: ancestorKey,
builder: (context) {
bucket.writeState(context, true);
return SizedBox(
width: 220,
child: AppSelect<int>(
label: 'Color space',
emptyLabel: 'No options',
value: 0,
options: const [
AppSelectOption(0, 'Automatic'),
AppSelectOption(1, 'Manual'),
],
onChanged: (value) => selected = value,
),
);
},
),
),
),
),
);
await tester.pumpAndSettle();
for (var i = 0; i < 2; i++) {
await tester.tap(find.text('Automatic'));
await tester.pumpAndSettle();
expect(tester.takeException(), isNull);
await tester.tap(find.text('Manual'));
await tester.pumpAndSettle();
expect(selected, 1);
expect(bucket.readState(tester.element(find.byKey(ancestorKey))), isTrue);
expect(tester.takeException(), isNull);
}
});
testWidgets(
'native menu waits for right-button release and dismissal keeps left clicks working',
(tester) async {
@@ -248,7 +537,7 @@ void main() {
await tester.tap(find.byType(TextButton));
await tester.pumpAndSettle();
expect(tester.takeException(), isNull);
expect(find.byIcon(Icons.check), findsOneWidget);
expect(find.byIcon(AppIcons.check), findsOneWidget);
expect(
tester.getSize(find.widgetWithText(MenuItemButton, 'Dark')).height,
28,
@@ -1,10 +1,70 @@
import 'package:cutdex_ui/theme.dart';
import 'package:cutdex_ui/widgets.dart';
import 'package:flutter/material.dart';
import 'package:flutter/gestures.dart';
import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('popover clears pointer focus and retains keyboard focus', (
tester,
) async {
final focus = FocusNode();
final states = WidgetStatesController();
addTearDown(focus.dispose);
addTearDown(states.dispose);
await tester.pumpWidget(
MaterialApp(
theme: AppTheme.penDark,
home: Scaffold(
body: Align(
alignment: Alignment.topLeft,
child: AppPopover(
builder: (_, toggle) => TextButton(
focusNode: focus,
statesController: states,
onPressed: toggle,
child: const Text('Open'),
),
child: const Text('Content'),
),
),
),
),
);
final mouse = await tester.createGesture(kind: PointerDeviceKind.mouse);
await mouse.addPointer(location: const Offset(400, 400));
for (final outside in [false, true]) {
final trigger = tester.getCenter(find.text('Open'));
await mouse.moveTo(trigger);
await mouse.down(trigger);
await mouse.up();
await tester.pumpAndSettle();
expect(find.text('Content'), findsOneWidget);
final closingPoint = outside ? const Offset(400, 400) : trigger;
await mouse.moveTo(closingPoint);
await mouse.down(closingPoint);
await mouse.up();
await mouse.moveTo(const Offset(450, 450));
await tester.pumpAndSettle();
expect(find.text('Content'), findsNothing);
expect(focus.hasFocus, isFalse);
expect(states.value, isNot(contains(WidgetState.focused)));
expect(states.value, isNot(contains(WidgetState.hovered)));
}
await mouse.removePointer();
focus.requestFocus();
await tester.pump();
await tester.sendKeyEvent(LogicalKeyboardKey.enter);
await tester.pumpAndSettle();
expect(find.text('Content'), findsOneWidget);
await tester.sendKeyEvent(LogicalKeyboardKey.escape);
await tester.pumpAndSettle();
expect(find.text('Content'), findsNothing);
expect(focus.hasFocus, isTrue);
expect(tester.takeException(), isNull);
});
testWidgets(
'popover anchors below its trigger and dismisses outside and with Escape',
(tester) async {
@@ -0,0 +1,74 @@
import 'package:cutdex_ui/theme.dart';
import 'package:cutdex_ui/widgets.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('titles and actions leave the full width for paired fields', (
tester,
) async {
for (final palette in AppPalette.values) {
for (final brightness in Brightness.values) {
await tester.pumpWidget(
MaterialApp(
theme: AppTheme.propertiesPanelTheme(
AppTheme.desktopWorkspaceTheme(
AppTheme.forPalette(palette, brightness),
),
),
home: Scaffold(
body: SizedBox(
width: 220,
child: Padding(
padding: const EdgeInsets.all(12),
child: AppPropertyGroup(
label: 'Position',
actions: [
IconButton(
onPressed: () {},
icon: const Icon(Icons.diamond_outlined),
),
],
child: const Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Expanded(
child: AppTextField(
label: 'X',
errorText: 'Invalid value',
),
),
SizedBox(width: 4),
Expanded(child: AppTextField(label: 'Y')),
],
),
),
),
),
),
),
);
await tester.pumpAndSettle();
final first = find.byType(TextField).first;
final second = find.byType(TextField).last;
expect(tester.getRect(first).width, 96);
expect(tester.getRect(second).right, 208);
expect(tester.getRect(first).top, tester.getRect(second).top);
expect(
tester.getRect(first).height,
greaterThan(tester.getRect(second).height),
);
expect(
tester.getRect(find.byType(IconButton)).bottom,
tester.getRect(first).top - 4,
);
expect(
tester.widget<TextField>(first).decoration!.prefixIcon,
isNotNull,
);
expect(tester.takeException(), isNull);
}
}
await tester.pumpWidget(const SizedBox());
});
}
+161
View File
@@ -7,6 +7,167 @@ import 'package:flutter/rendering.dart';
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('slider density follows inspector and desktop contexts', (
tester,
) async {
final desktop = AppTheme.desktopWorkspaceTheme(AppTheme.penDark);
for (final (theme, height) in [
(AppTheme.propertiesPanelTheme(desktop), 28.0),
(desktop, 36.0),
(
AppTheme.propertiesPanelTheme(AppTheme.penDark),
AppControlSize.standard,
),
]) {
await tester.pumpWidget(
MaterialApp(
theme: theme,
home: Scaffold(
body: Center(
child: SizedBox(
width: 220,
child: AppSlider(value: .5, onChanged: (_) {}),
),
),
),
),
);
await tester.pumpAndSettle();
expect(tester.getSize(find.byType(AppSlider)).height, height);
expect(tester.takeException(), isNull);
}
});
test(
'inspector density leaves general desktop and touch inputs unchanged',
() {
final desktop = AppTheme.desktopWorkspaceTheme(AppTheme.penDark);
final inspector = AppTheme.propertiesPanelTheme(desktop);
expect(desktop.inputDecorationTheme.constraints!.minHeight, 36);
expect(inspector.inputDecorationTheme.constraints!.minHeight, 28);
expect(inspector.textTheme.bodyMedium!.fontSize, 13);
expect(inspector.textTheme.bodySmall!.fontSize, 12);
expect(
inspector.iconButtonTheme.style!.fixedSize!.resolve({}),
const Size.square(24),
);
expect(desktop.extension<InspectorControlDensity>(), isNull);
expect(inspector.extension<InspectorControlDensity>(), isNotNull);
final dialog = AppTheme.dialogContentTheme(inspector);
expect(dialog.extension<InspectorControlDensity>(), isNull);
expect(dialog.inputDecorationTheme.constraints!.minHeight, 36);
expect(dialog.textTheme.bodyMedium!.fontSize, 14);
final touch = AppTheme.propertiesPanelTheme(AppTheme.penDark);
expect(touch.extension<InspectorControlDensity>(), isNull);
expect(
touch.iconButtonTheme.style!.fixedSize!.resolve({}),
const Size.square(28),
);
},
);
testWidgets('multiline input keeps its first line near the top', (
tester,
) async {
final controller = TextEditingController(text: 'First\nSecond');
addTearDown(controller.dispose);
await tester.pumpWidget(
MaterialApp(
theme: AppTheme.desktopWorkspaceTheme(AppTheme.penDark),
home: Scaffold(
body: Center(
child: SizedBox(
width: 240,
height: 100,
child: AppTextField(
controller: controller,
minLines: 3,
maxLines: 3,
),
),
),
),
),
);
await tester.pumpAndSettle();
final editable = tester
.state<EditableTextState>(find.byType(EditableText))
.renderEditable;
final caret = editable.getLocalRectForCaret(const TextPosition(offset: 0));
expect(
editable.localToGlobal(caret.center).dy -
tester.getTopLeft(find.byType(TextField)).dy,
lessThan(25),
);
expect(tester.takeException(), isNull);
await tester.pumpWidget(const SizedBox());
});
testWidgets('labelled single-line inputs keep text and caret centered', (
tester,
) async {
final controller = TextEditingController(text: '125');
addTearDown(controller.dispose);
for (final brightness in Brightness.values) {
for (final desktop in [false, true]) {
final base = AppTheme.forPalette(AppPalette.graphite, brightness);
final theme = AppTheme.propertiesPanelTheme(
desktop ? AppTheme.desktopWorkspaceTheme(base) : base,
);
final height = desktop
? AppInspectorMetrics.input
: AppControlSize.propertyControl;
await tester.pumpWidget(
MaterialApp(
theme: theme,
home: Scaffold(
body: Center(
child: SizedBox(
width: 240,
height: height,
child: AppTextField(
controller: controller,
label: 'W',
unit: '%',
hintText: 'Value',
),
),
),
),
),
);
await tester.pumpAndSettle();
final field = find.byType(TextField);
final label = find.text('W');
expect(
tester.getRect(label).center.dy,
tester.getRect(field).center.dy,
);
expect(
tester.widget<TextField>(field).decoration!.prefixIcon,
isNotNull,
);
for (final text in ['', '125', '项目']) {
await tester.enterText(field, text);
await tester.pump();
final editable = tester
.state<EditableTextState>(find.byType(EditableText))
.renderEditable;
final caret = editable.getLocalRectForCaret(
TextPosition(offset: text.length),
);
expect(
editable.localToGlobal(caret.center).dy,
closeTo(tester.getCenter(field).dy, 1),
);
expect(tester.getSize(field).height, height);
expect(tester.takeException(), isNull);
}
await tester.pumpWidget(const SizedBox());
}
}
});
test('Icon button states use translucent ink without stacking selection', () {
final style = AppTheme.penDark.iconButtonTheme.style!;
const ink = Color(0xFFFCFCFC);
@@ -0,0 +1,129 @@
import 'package:cutdex_ui/theme.dart';
import 'package:cutdex_ui/widgets.dart';
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
void main() {
for (final kind in ['searchable', 'popover', 'context']) {
for (final stored in <Object>[true, 120.0]) {
testWidgets('$kind popup isolates ancestor state $stored', (
tester,
) async {
final bucket = PageStorageBucket();
const ancestorKey = PageStorageKey('parent-state');
Widget popup() => switch (kind) {
'searchable' => AppSelect<int>(
value: 0,
label: 'Select',
emptyLabel: 'Empty',
searchable: true,
searchHint: 'Search',
onChanged: (_) {},
options: [
for (var i = 0; i < 40; i++) AppSelectOption(i, 'Choice $i'),
],
),
'popover' => AppPopover(
builder: (_, toggle) => TextButton(
key: const Key('trigger'),
onPressed: toggle,
child: const Text('Open'),
),
child: SizedBox(
height: 150,
child: ListView(
primary: false,
children: [
for (var i = 0; i < 40; i++)
SizedBox(height: 32, child: Text('Choice $i')),
],
),
),
),
_ => AppContextMenu(
itemsBuilder: (_) => [
for (var i = 0; i < 40; i++)
AppMenuItem(label: 'Choice $i', onPressed: () {}),
],
child: const SizedBox(
key: Key('trigger'),
width: 200,
height: 100,
child: ColoredBox(color: Colors.transparent),
),
),
};
await tester.pumpWidget(
MaterialApp(
theme: AppTheme.penDark,
home: Scaffold(
body: Align(
alignment: Alignment.topLeft,
child: SizedBox(
width: 240,
child: PageStorage(
bucket: bucket,
child: Builder(
key: ancestorKey,
builder: (context) {
bucket.writeState(context, stored);
return popup();
},
),
),
),
),
),
),
);
await tester.pumpAndSettle();
await tester.tap(
kind == 'searchable'
? find.byType(TextField)
: find.byKey(const Key('trigger')),
buttons: kind == 'context'
? kSecondaryMouseButton
: kPrimaryMouseButton,
);
await tester.pumpAndSettle();
expect(tester.takeException(), isNull);
final positions = tester
.stateList<ScrollableState>(
find.byWidgetPredicate(
(widget) =>
widget is Scrollable &&
axisDirectionToAxis(widget.axisDirection) == Axis.vertical,
),
)
.map((state) => state.position)
.toList();
expect(positions, isNotEmpty);
for (final position in positions) {
expect(
position.pixels,
0,
reason: 'Popup must not restore its parent offset',
);
}
positions
.firstWhere((position) => position.maxScrollExtent > 50)
.jumpTo(25);
await tester.pumpAndSettle();
expect(
bucket.readState(tester.element(find.byKey(ancestorKey))),
stored,
);
await tester.tapAt(const Offset(790, 590));
await tester.pumpAndSettle();
expect(find.text('Choice 3'), findsNothing);
expect(
bucket.readState(tester.element(find.byKey(ancestorKey))),
stored,
);
expect(tester.takeException(), isNull);
await tester.pumpWidget(const SizedBox());
});
}
}
}