feat(workspace): add workflow navigation and resizable desktop panels
This commit is contained in:
1 parent
02413383d8
commit
1acfe4a005
17 files changed
+2008
-277
No files matched your search
@@ -5,107 +5,244 @@ import 'package:flutter/rendering.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
for (final axis in Axis.values) {
|
||||
for (final finish in ['release', 'cancel', 'unmount']) {
|
||||
testWidgets('$axis resize cursor stays locked until $finish', (
|
||||
tester,
|
||||
) async {
|
||||
var showHandle = true;
|
||||
var taps = 0;
|
||||
var ends = 0;
|
||||
var starts = 0;
|
||||
var updates = 0;
|
||||
late StateSetter update;
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: Scaffold(
|
||||
body: StatefulBuilder(
|
||||
builder: (context, setState) {
|
||||
update = setState;
|
||||
return Stack(
|
||||
children: [
|
||||
Positioned(
|
||||
left: 400,
|
||||
top: 400,
|
||||
width: 100,
|
||||
height: 60,
|
||||
child: MouseRegion(
|
||||
cursor: SystemMouseCursors.click,
|
||||
child: GestureDetector(
|
||||
key: const Key('button'),
|
||||
onTap: () => taps++,
|
||||
child: const ColoredBox(color: Colors.blue),
|
||||
),
|
||||
),
|
||||
for (final axis in [...Axis.values, null]) {
|
||||
testWidgets('$axis feedback fades and expands with rounded ends', (
|
||||
tester,
|
||||
) async {
|
||||
final handle = find.byKey(const Key('animated-handle'));
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: Scaffold(
|
||||
body: Center(
|
||||
child: SizedBox(
|
||||
width: axis == Axis.vertical ? 200 : 10,
|
||||
height: axis == Axis.horizontal ? 200 : 10,
|
||||
child: axis == null
|
||||
? WorkspaceResizeHandle.junction(
|
||||
key: const Key('animated-handle'),
|
||||
initialWidth: 100,
|
||||
initialHeight: 100,
|
||||
onWidthChanged: (_) {},
|
||||
onHeightChanged: (_) {},
|
||||
)
|
||||
: WorkspaceResizeHandle(
|
||||
key: const Key('animated-handle'),
|
||||
axis: axis,
|
||||
initialValue: 100,
|
||||
onResize: (_) {},
|
||||
),
|
||||
if (showHandle)
|
||||
Positioned(
|
||||
left: 100,
|
||||
top: 100,
|
||||
width: axis == Axis.horizontal ? 5 : 200,
|
||||
height: axis == Axis.horizontal ? 200 : 5,
|
||||
child: WorkspaceResizeHandle(
|
||||
key: const Key('handle'),
|
||||
axis: axis,
|
||||
initialValue: 100,
|
||||
onStart: () => starts++,
|
||||
onResize: (_) {
|
||||
expect(starts, 1);
|
||||
updates++;
|
||||
},
|
||||
onEnd: () => ends++,
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
final mouse = await tester.createGesture(kind: PointerDeviceKind.mouse);
|
||||
final start = tester.getCenter(find.byKey(const Key('handle')));
|
||||
final button = tester.getCenter(find.byKey(const Key('button')));
|
||||
await mouse.addPointer(location: start);
|
||||
await mouse.down(start);
|
||||
await mouse.moveBy(
|
||||
axis == Axis.horizontal ? const Offset(30, 0) : const Offset(0, 30),
|
||||
);
|
||||
await tester.pump();
|
||||
await mouse.moveTo(button);
|
||||
await tester.pump();
|
||||
expect(updates, greaterThan(0));
|
||||
expect(starts, 1);
|
||||
expect(
|
||||
RendererBinding.instance.mouseTracker.debugDeviceActiveCursor(1),
|
||||
axis == Axis.horizontal
|
||||
? SystemMouseCursors.resizeColumn
|
||||
: SystemMouseCursors.resizeRow,
|
||||
);
|
||||
// A second pointer still reaches the control through the cursor overlay.
|
||||
await tester.tap(find.byKey(const Key('button')));
|
||||
expect(taps, 1);
|
||||
),
|
||||
);
|
||||
final fade = find.descendant(of: handle, matching: find.byType(Opacity));
|
||||
final paint = find.descendant(
|
||||
of: handle,
|
||||
matching: find.byType(DecoratedBox),
|
||||
);
|
||||
double opacity() => tester.widget<Opacity>(fade).opacity;
|
||||
final hitSize = tester.getSize(handle);
|
||||
final center = tester.getCenter(handle);
|
||||
final mouse = await tester.createGesture(kind: PointerDeviceKind.mouse);
|
||||
expect(opacity(), 0);
|
||||
await mouse.addPointer(location: center);
|
||||
await tester.pump();
|
||||
expect(opacity(), 0);
|
||||
await tester.pump(const Duration(milliseconds: 60));
|
||||
expect(opacity(), inExclusiveRange(0, 1));
|
||||
final growing = tester.getRect(paint);
|
||||
expect(
|
||||
axis == Axis.vertical ? growing.height : growing.width,
|
||||
inExclusiveRange(2, 4),
|
||||
);
|
||||
expect(tester.getSize(handle), hitSize);
|
||||
await tester.pumpAndSettle();
|
||||
expect(opacity(), 1);
|
||||
final decoration =
|
||||
tester.widget<DecoratedBox>(paint).decoration as BoxDecoration;
|
||||
expect(decoration.borderRadius, BorderRadius.circular(2));
|
||||
await mouse.moveTo(const Offset(10, 10));
|
||||
await tester.pump();
|
||||
await tester.pump(const Duration(milliseconds: 30));
|
||||
final fading = opacity();
|
||||
expect(fading, inExclusiveRange(0, 1));
|
||||
// Reentering mid-fade continues from its current appearance.
|
||||
await mouse.moveTo(center);
|
||||
await tester.pump();
|
||||
expect(opacity(), closeTo(fading, .001));
|
||||
await tester.pumpAndSettle();
|
||||
expect(opacity(), 1);
|
||||
await mouse.moveTo(const Offset(10, 10));
|
||||
await tester.pumpAndSettle();
|
||||
expect(opacity(), 0);
|
||||
await mouse.removePointer();
|
||||
expect(tester.takeException(), isNull);
|
||||
});
|
||||
}
|
||||
|
||||
if (finish == 'unmount') {
|
||||
update(() => showHandle = false);
|
||||
for (final axis in [...Axis.values, null]) {
|
||||
for (final finish in ['release', 'cancel', 'unmount']) {
|
||||
testWidgets(
|
||||
'$axis resize cursor stays locked until $finish',
|
||||
(tester) async {
|
||||
final expectedCursor = axis == null
|
||||
? SystemMouseCursors.grab
|
||||
: axis == Axis.horizontal
|
||||
? SystemMouseCursors.resizeColumn
|
||||
: SystemMouseCursors.resizeRow;
|
||||
var showHandle = true;
|
||||
var taps = 0;
|
||||
var ends = 0;
|
||||
var starts = 0;
|
||||
var updates = 0;
|
||||
late StateSetter update;
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: Scaffold(
|
||||
body: StatefulBuilder(
|
||||
builder: (context, setState) {
|
||||
update = setState;
|
||||
return Stack(
|
||||
children: [
|
||||
Positioned(
|
||||
left: 400,
|
||||
top: 400,
|
||||
width: 100,
|
||||
height: 60,
|
||||
child: MouseRegion(
|
||||
cursor: SystemMouseCursors.click,
|
||||
child: GestureDetector(
|
||||
key: const Key('button'),
|
||||
onTap: () => taps++,
|
||||
child: const ColoredBox(color: Colors.blue),
|
||||
),
|
||||
),
|
||||
),
|
||||
if (showHandle)
|
||||
Positioned(
|
||||
left: 100,
|
||||
top: 100,
|
||||
width: axis == null || axis == Axis.horizontal
|
||||
? 5
|
||||
: 200,
|
||||
height: axis == null || axis == Axis.vertical
|
||||
? 5
|
||||
: 200,
|
||||
child: axis == null
|
||||
? WorkspaceResizeHandle.junction(
|
||||
key: const Key('handle'),
|
||||
initialWidth: 100,
|
||||
initialHeight: 100,
|
||||
onStart: () => starts++,
|
||||
onWidthChanged: (_) {
|
||||
expect(starts, 1);
|
||||
updates++;
|
||||
},
|
||||
onHeightChanged: (_) {
|
||||
expect(starts, 1);
|
||||
updates++;
|
||||
},
|
||||
onEnd: () => ends++,
|
||||
)
|
||||
: WorkspaceResizeHandle(
|
||||
key: const Key('handle'),
|
||||
axis: axis,
|
||||
initialValue: 100,
|
||||
onStart: () => starts++,
|
||||
onResize: (_) {
|
||||
expect(starts, 1);
|
||||
updates++;
|
||||
},
|
||||
onEnd: () => ends++,
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
final mouse = await tester.createGesture(
|
||||
kind: PointerDeviceKind.mouse,
|
||||
);
|
||||
final start = tester.getCenter(find.byKey(const Key('handle')));
|
||||
final button = tester.getCenter(find.byKey(const Key('button')));
|
||||
double highlightOpacity() => tester
|
||||
.widget<Opacity>(
|
||||
find.descendant(
|
||||
of: find.byKey(const Key('handle')),
|
||||
matching: find.byType(Opacity),
|
||||
),
|
||||
)
|
||||
.opacity;
|
||||
expect(highlightOpacity(), 0);
|
||||
await mouse.addPointer(location: start);
|
||||
await tester.pumpAndSettle();
|
||||
await mouse.up();
|
||||
} else if (finish == 'cancel') {
|
||||
await mouse.cancel();
|
||||
} else {
|
||||
await mouse.up();
|
||||
}
|
||||
await tester.pumpAndSettle();
|
||||
await mouse.moveTo(button + const Offset(1, 0));
|
||||
await tester.pump();
|
||||
expect(
|
||||
RendererBinding.instance.mouseTracker.debugDeviceActiveCursor(1),
|
||||
SystemMouseCursors.click,
|
||||
);
|
||||
expect(ends, finish == 'unmount' ? 0 : 1);
|
||||
await mouse.removePointer();
|
||||
expect(tester.takeException(), isNull);
|
||||
});
|
||||
expect(highlightOpacity(), 1);
|
||||
expect(
|
||||
RendererBinding.instance.mouseTracker.debugDeviceActiveCursor(1),
|
||||
expectedCursor,
|
||||
);
|
||||
await mouse.down(start);
|
||||
await mouse.moveBy(
|
||||
axis == null
|
||||
? const Offset(30, 30)
|
||||
: axis == Axis.horizontal
|
||||
? const Offset(30, 0)
|
||||
: const Offset(0, 30),
|
||||
);
|
||||
await tester.pump();
|
||||
await mouse.moveTo(button);
|
||||
await tester.pump();
|
||||
expect(updates, greaterThan(0));
|
||||
expect(starts, 1);
|
||||
expect(highlightOpacity(), 1);
|
||||
expect(
|
||||
RendererBinding.instance.mouseTracker.debugDeviceActiveCursor(1),
|
||||
axis == null ? SystemMouseCursors.grabbing : expectedCursor,
|
||||
);
|
||||
// A second pointer still reaches the control through the cursor overlay.
|
||||
await tester.tap(find.byKey(const Key('button')));
|
||||
expect(taps, 1);
|
||||
|
||||
if (finish == 'unmount') {
|
||||
update(() => showHandle = false);
|
||||
await tester.pumpAndSettle();
|
||||
await mouse.up();
|
||||
} else if (finish == 'cancel') {
|
||||
await mouse.cancel();
|
||||
} else {
|
||||
await mouse.up();
|
||||
}
|
||||
await tester.pumpAndSettle();
|
||||
await mouse.moveTo(button + const Offset(1, 0));
|
||||
await tester.pump();
|
||||
expect(
|
||||
RendererBinding.instance.mouseTracker.debugDeviceActiveCursor(1),
|
||||
SystemMouseCursors.click,
|
||||
);
|
||||
expect(ends, finish == 'unmount' ? 0 : 1);
|
||||
if (finish != 'unmount') {
|
||||
expect(highlightOpacity(), 0);
|
||||
await mouse.moveTo(start);
|
||||
await tester.pumpAndSettle();
|
||||
expect(highlightOpacity(), 1);
|
||||
expect(
|
||||
RendererBinding.instance.mouseTracker.debugDeviceActiveCursor(1),
|
||||
expectedCursor,
|
||||
);
|
||||
}
|
||||
await mouse.removePointer();
|
||||
expect(tester.takeException(), isNull);
|
||||
},
|
||||
variant: const TargetPlatformVariant({
|
||||
TargetPlatform.macOS,
|
||||
TargetPlatform.windows,
|
||||
TargetPlatform.linux,
|
||||
}),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user