I have a widget UnkownWidget()
(let’s say the sample counter from Flutter) :
What I would like to create is a widget that displays its child next to a duplication of its view:
WithPreviewOnTheRight(
child: UnknownWidget(),
),
What I would like WithPreviewOnTheRight
to do is to display its child on the left, and a preview/screening/duplication on the right:
I want the 2 instances to be "the same" (aka sharing the same state). When I interact with the widget on the left, the changes are also visible on the widget on the right.
The widget on the right doesn’t have to be interactive, I am planning to wrap it with an IgnorePointer
. I just want it to be a "rediffusion" / "screening" of the main one on the left.
Using a Row
as in
Row(
children: [
Expanded(
child: child,
),
Expanded(
child: child,
),
],
),
wouldn’t work as the 2 "views" wouldn’t share the same state.
How can I duplicate the "view" of a widget?
2
Answers
Ok, let’s see if I understood what you want to achieve.
The Widget approach:
Create a widget class for your component, which you can call multiple instances which might not be entirely disconnected between them, if you have a common controller that is used to set their state, making them clones of each other.
The Method approach:
Just like before, but instead of creating a class, you create a function that returns the Widget.
These methods might create an exact clone of the element that you want, without the Widget state management part in it.
in both approaches, you can call the element by writing
EmptyScreen()
on your widget tree.Just be aware that any constraints like height, and width are not set by default, and might depend on the parent of the element where you place your self-made widgets.
To make sure both have the same aspect, you might need to track the size of one of them, and manually set the values of the clone.
I hope this helped. 👍
I think what you want is to paint the child another time, next to the old one. And you won’t be able to interact with the second one.