A widget that follows the size of another widget (on a one-frame delay)
As pointed out in https://github.com/flutter/flutter/issues/45719#issuecomment-2896769612 , there is an imo simpler way of doing the drag and drop use case. I should alter the readme. For posterity, it said: > The motivating usecase was a drag and drop widget, where when a widget is dragged, it needs to leave behind an empty SizedBox of the same size as the widget being dragged, to keep layout in the container from jumping around. It's rare that the size of the widget being dragged changes mid-drag, so the size will start out correct and stay correct as long as it needs to, but even if it did change, you wouldn't notice the lag, since they'd be in quite different places on the screen. And indeed the code for that looked quite simple ```dart final pb = DraggableFeedbackPositionBox(); return LongPressDraggable( delay: const Duration(milliseconds: 290), feedback: result, // I think this requires a second globalkey to narrow in on transferrable or something :/ and a listener childWhenDragging: SizeFollower( previousSize: previousSize, ), child: SizeReporter( previousSize: previousSize, child: result)); ``` Only, the whole size_follower library introduces extra functionality that we don't really want (updating the size mid-drag) and isn't really necessary given that we could also just do this: ```dart class DraggableWidget extends StatefulWidget { final Widget child; const DraggableWidget({super.key, required this.child}); @override State<DraggableWidget> createState() => _DraggableWidgetState(); } class _DraggableWidgetState extends State<DraggableWidget> { final previousSize = ValueNotifier<Size?>(null); @override Widget build(BuildContext context) { return ValueListenableBuilder( valueListenable: previousSize, builder: (context, size, child) { return LongPressDraggable( feedback: widget.child, onDragStarted: () { previousSize.value = context.size; }, childWhenDragging: SizedBox(width: size?.width ?? 0, height: size?.height ?? 0), child: widget.child); }, ); } @override void dispose() { previousSize.dispose(); super.dispose(); } } ``` ```dart return DraggableWidget(child: result); ```
This issue appears to be discussing a feature request or bug report related to the repository. Based on the content, it seems to be still under discussion. The issue was opened by makoConstruct and has received 0 comments.