Drag chats at once with a mouse and mark only the receiving zone
The list rows used a long-press drag, which a mouse rarely triggers; they now drag immediately with the chip at the pointer. The drop indicator outlines just the area that will receive the chat (the pane, or the right or bottom half) with a label saying what happens.
This commit is contained in:
@@ -126,7 +126,10 @@ class ChatCompactSidebar extends StatelessWidget {
|
||||
? Duration.zero
|
||||
: const Duration(milliseconds: 200),
|
||||
color: selected ? Colors.transparent : color.withValues(alpha: .07),
|
||||
child: LongPressDraggable<JsonMap>(
|
||||
child: Draggable<JsonMap>(
|
||||
// A mouse drags at once (a click still opens the chat); the chip
|
||||
// follows the pointer.
|
||||
dragAnchorStrategy: pointerDragAnchorStrategy,
|
||||
data: row,
|
||||
feedback: Material(
|
||||
elevation: 4,
|
||||
|
||||
@@ -81,7 +81,10 @@ class ChatSessionRow extends StatelessWidget {
|
||||
marker: marker,
|
||||
markerWidth: visible ? (selected ? 10 : 3) : 0,
|
||||
child: draggable
|
||||
? LongPressDraggable<JsonMap>(
|
||||
? Draggable<JsonMap>(
|
||||
// A mouse drags at once (a click still opens the chat); the chip
|
||||
// follows the pointer.
|
||||
dragAnchorStrategy: pointerDragAnchorStrategy,
|
||||
data: session,
|
||||
feedback: Material(
|
||||
elevation: 4,
|
||||
|
||||
@@ -57,38 +57,77 @@ class _ChatWorkspaceDropTargetState extends State<ChatWorkspaceDropTarget> {
|
||||
builder: (context, candidates, rejected) {
|
||||
final zone = _zone;
|
||||
if (zone == null) return const SizedBox.expand();
|
||||
final color = Theme.of(context).colorScheme.primary;
|
||||
final indicator = switch (zone) {
|
||||
ChatWorkspaceDropZone.replace => const SizedBox.expand(),
|
||||
ChatWorkspaceDropZone.right => const Align(
|
||||
alignment: Alignment.centerRight,
|
||||
child: FractionallySizedBox(widthFactor: .5, heightFactor: 1),
|
||||
final scheme = Theme.of(context).colorScheme;
|
||||
final (alignment, width, height, icon, label) = switch (zone) {
|
||||
ChatWorkspaceDropZone.replace => (
|
||||
Alignment.center,
|
||||
1.0,
|
||||
1.0,
|
||||
Icons.swap_horiz,
|
||||
'Show here',
|
||||
),
|
||||
ChatWorkspaceDropZone.bottom => const Align(
|
||||
alignment: Alignment.bottomCenter,
|
||||
child: FractionallySizedBox(widthFactor: 1, heightFactor: .5),
|
||||
ChatWorkspaceDropZone.right => (
|
||||
Alignment.centerRight,
|
||||
.5,
|
||||
1.0,
|
||||
Icons.vertical_split_outlined,
|
||||
'Open to the right',
|
||||
),
|
||||
ChatWorkspaceDropZone.bottom => (
|
||||
Alignment.bottomCenter,
|
||||
1.0,
|
||||
.5,
|
||||
Icons.horizontal_split_outlined,
|
||||
'Open below',
|
||||
),
|
||||
};
|
||||
return Stack(
|
||||
fit: StackFit.expand,
|
||||
children: [
|
||||
DecoratedBox(
|
||||
decoration: BoxDecoration(color: color.withValues(alpha: .18)),
|
||||
child: indicator,
|
||||
),
|
||||
if (zone != ChatWorkspaceDropZone.replace)
|
||||
Align(
|
||||
alignment: zone == ChatWorkspaceDropZone.right
|
||||
? Alignment.centerRight
|
||||
: Alignment.bottomCenter,
|
||||
child: Icon(
|
||||
zone == ChatWorkspaceDropZone.right
|
||||
? Icons.vertical_split
|
||||
: Icons.horizontal_split,
|
||||
color: color,
|
||||
// Only the area that will receive the chat is marked: the whole pane
|
||||
// to replace its chat, or the half a new split will take.
|
||||
return IgnorePointer(
|
||||
child: Align(
|
||||
alignment: alignment,
|
||||
child: FractionallySizedBox(
|
||||
widthFactor: width,
|
||||
heightFactor: height,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(8),
|
||||
child: DecoratedBox(
|
||||
key: ValueKey('chat-drop-zone-${zone.name}'),
|
||||
decoration: BoxDecoration(
|
||||
color: scheme.primary.withValues(alpha: .14),
|
||||
border: Border.all(color: scheme.primary, width: 2),
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
),
|
||||
child: Center(
|
||||
child: DecoratedBox(
|
||||
decoration: BoxDecoration(
|
||||
color: scheme.primaryContainer,
|
||||
borderRadius: BorderRadius.circular(24),
|
||||
),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 16,
|
||||
vertical: 10,
|
||||
),
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Icon(icon, color: scheme.onPrimaryContainer),
|
||||
const SizedBox(width: 8),
|
||||
Text(
|
||||
label,
|
||||
style: Theme.of(context).textTheme.labelLarge
|
||||
?.copyWith(color: scheme.onPrimaryContainer),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
@@ -0,0 +1,78 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/features/chat/workspace/chat_workspace_drop.dart';
|
||||
import 'package:pipelines_app/features/chat/workspace/chat_workspace_nodes.dart';
|
||||
|
||||
void main() {
|
||||
Future<List<ChatWorkspaceDropZone>> pumpPane(WidgetTester tester) async {
|
||||
tester.view.physicalSize = const Size(1200, 800);
|
||||
tester.view.devicePixelRatio = 1;
|
||||
addTearDown(tester.view.reset);
|
||||
final drops = <ChatWorkspaceDropZone>[];
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: Scaffold(
|
||||
body: Row(
|
||||
children: [
|
||||
const SizedBox(
|
||||
width: 200,
|
||||
child: Draggable<String>(
|
||||
data: 'b',
|
||||
// As the chat list does: the feedback sits at the pointer.
|
||||
dragAnchorStrategy: pointerDragAnchorStrategy,
|
||||
feedback: Text('chat b'),
|
||||
child: Text('source'),
|
||||
),
|
||||
),
|
||||
SizedBox(
|
||||
width: 800,
|
||||
height: 600,
|
||||
child: ChatWorkspaceDropTarget(
|
||||
pane: const ChatWorkspacePane('pane-a', 'a'),
|
||||
rect: const Rect.fromLTWH(0, 0, 800, 600),
|
||||
onDrop: (_, _, zone) => drops.add(zone),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
return drops;
|
||||
}
|
||||
|
||||
// The pane occupies x 200..1000, y 0..600.
|
||||
for (final (name, point, zone) in [
|
||||
('centre', const Offset(500, 250), ChatWorkspaceDropZone.replace),
|
||||
('right edge', const Offset(950, 250), ChatWorkspaceDropZone.right),
|
||||
('bottom edge', const Offset(500, 560), ChatWorkspaceDropZone.bottom),
|
||||
]) {
|
||||
testWidgets('a mouse drag over the $name marks only that zone and drops '
|
||||
'there', (tester) async {
|
||||
final drops = await pumpPane(tester);
|
||||
final gesture = await tester.startGesture(
|
||||
tester.getCenter(find.text('source')),
|
||||
);
|
||||
// No long press: a plain drag starts at once.
|
||||
await gesture.moveBy(const Offset(20, 0));
|
||||
await gesture.moveTo(point);
|
||||
await tester.pump();
|
||||
await tester.pump();
|
||||
expect(
|
||||
find.byKey(ValueKey('chat-drop-zone-${zone.name}')),
|
||||
findsOneWidget,
|
||||
);
|
||||
for (final other in ChatWorkspaceDropZone.values) {
|
||||
if (other == zone) continue;
|
||||
expect(
|
||||
find.byKey(ValueKey('chat-drop-zone-${other.name}')),
|
||||
findsNothing,
|
||||
);
|
||||
}
|
||||
await gesture.up();
|
||||
await tester.pump();
|
||||
expect(drops, [zone]);
|
||||
expect(find.byKey(ValueKey('chat-drop-zone-${zone.name}')), findsNothing);
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user