Flutter: Change location injection in widget tree of DropDownMenuItem - flutter

I am using a DropdownButton in a Flutter app, and when you click it and the drop down appears, it overlays a webview that I'm using.
That all works perfectly, however webviews in Flutter, when run as a web app (which this is) trap all UI interactions and don't allow clicks to flow through to the Flutter UI elements.
There is a PointerInterceptor component that handles this perfectly, all I need to be able to do is wrap all of the DropdownMenuItems that appear inside of a single pointer interceptor (because if I individually wrap them then there is a really bad performance hit).
However - the DropdownMenuItems appear in the widget tree directly under the MaterialApp widget - and that is too high in the tree for me to wrap in a PointerInterceptor.
That is the reason that I want to know :
Is it possible to specify where in the widget tree the DropdownMenuItem widgets' appear when a DropdownMenuButton is clicked ?

Related

Refresh a widget programmatically

I'm developing an app in Flutter, and I'm stuck with this: I have a list of widgets that I generate dynamically. When I press a button, I need to show or hide one of the widgets in the list. I use the Visible widget to show or hide them.
The problem is that I need to know how to update any of the specific widgets in my widget list as they are dynamic and are separated, it is getting complicated doing int programmatically.
How can I do it?
PS: I have the same app developed in Android Studio and I do it by traversing for example the child Views of a LinearLayout and then I ask for its id programmatically.

Flutter Recreating the Hero Transition replacing Navigator with a custom Animator

Looking at the Flutter Hero Transition, it appears to move the tagged Widgets to an Overlay class that exists in all Navigator Widgets but sits above the main content in the stack.
If this is correct, it allows the Hero to widgets to still respond to the Route scope and its animators but exist above the actual route content. How is this actually done efficiently? Surely this involves taking an entire Widget and storing it in a state for the duration of the animation. That Widget still has to respond to intrinsic responses from its original position such as slivers responding to active scroll actions.
Recreating this could be done with state management but I wondered how the standard hero actually does this. It seems like Widgets are effectively duplicated and then conditionally rendered on the screen defaulting to the overlay during the route animation and swapping out the original widget with an Offstage or similar. Is this how it is done?
The reason for trying to understand it is the need to replicate this behaviour in situations where Navigator is not an effective use case for a transition taking place internally on a page. I built an accordion style navigator but still want a hero transition to take place on the AppBar / NavigationBar. I know that this could be done with Navigator but it doesn't suit the use case. I could also predefine the AppBar content for each internal navigator state of the accordion but that is a lot of additional code.

Using Riverpod for Flutter state, what's better: ConsumerWidget or just a Consumer where needed?

I'm fairly new to Riverpod but it seems that using a ConsumerWidget as the body of a screen is a bad practice because the screen is rebuilt when not needed.
For example:
the main widget (the screen itself) is a ConsumerWidget
somewhere in the hierarchy I have a list of clickable buttons, for which I'm watching a ChangeNotifierProvider to update a selected index (only one button can be clicked at a time).
It seems that whenever I click one button to update the index (and change the color of the button), the main widget's Build method is called, along with the items in my list.
However, when using just a Consumer widget inside the itemBuilder method of my ListView, clicking one button no longer triggers the build method of the main widget.
So, is it considered a good practice to just use Consumer widgets where needed?

Can I store a widget from widget and later use it in another page without rebuilding it from scratch? - Flutter

I have a Stateful widget called Widget1 shown in one page. When I open my app the widget1 gets build from scratch and shown in the page. Let's assume the widget1 is quite heavy with lot's of other widget's inside it.
Now I want to display the same widget in another page but I don't want to build the same widget1 from scratch like I did in the first page. I want to reuse the widget which was built in the Previous page to be shown in this page.
Is that possible in flutter? I know flutter must build a widget inorder to make changes in Ui. But is this really possible? that is , to store a widget and use it, whenever we want without having to rebuild it, again from scratch?.

flutter how to get size of widgets before building

I'd like to fit multiple widgets into PageView,
if the page is full, I want to move to the next page.
So I'd like to get sizes of the widgets inside the page without building the widgets.
This post seems that it's required to build the widget first before getting the size.
For text, I can do it using RenderParagraph.
Is it possible to get the size of custom widgets?
The widgets I want to get the size are basically text which we can tab each word.