Flutter and Flame, how to keep FlameGame widget alive? - flutter

Working on a game project where:
I have a BottomNavigationBar navigating betwen my custom Widgets where one of them is a FlameGame. I don't want to unload and reload the widgets when player navigates as it will be frequent and expensive.
I have followed this and now my custom Widgets are being preserved, except for the FlameGame.
Tried adding AutomaticKeepAliveClientMixin. Wanted me to implement 12 overrides... Any suggestions?

Wrapped my GameWidget in another custom widget of mine that implements the KeepAlive mixin.
It works now.

Related

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.

Flutter: Change location injection in widget tree of DropDownMenuItem

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 ?

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?

How widgets are different from UI components?

I read everywhere on internet, in flutter everything is a widget but what actually widget is.I thinks its simply contain a bunch of properties that flutter need to render something on screen.But If widget is same as UI component then why we specially called it (Widget),like other languages we simply called UI components.Is Widgets same as UI component?
A widget is just a class that extends either the StatefulWidget or StatelessWidget classes.
It is also not really true that everything in flutter is a widget, but a lot of things are widgets. There are a hierarchy of widgets from the whole app itself to the containers or texts you have on the page, and everything in between. Lots of code you write for your app might be outside of these widget classes, and just interact with them.

How to prevent Stateful Widget stored in List to be disposed?

Let me start by explaining the problem. I have several buttons which are created based on data I'm getting from a server. On each button click I need to create and display a widget which will present me some data (this widget is also built dynamically). The state of this widget has to be preserved during the lifetime of the app. (for example if I click another button and show a different widget, I need to be able to click on the first button and show the first widget in its preserved state). Number of buttons can also be changed during the app lifetime.
I tried using IndexedStack to achieve this, but when the number of buttons is changed I need to add "pages" to IndexedStack, therefore I need to recreate a new IndexedStack which will have some of my old widgets, so I pull widgets from a List or create new ones if needed. This works great, except Flutter calls dispose() method on my widgets which are stored in the list. I tried using the AutomaticKeepAliveClientMixIn but it didn't help.
I'm guessing this has something to do that the widgets get detached from the parent, but when I reattach them to new parent (new Indexed stack) Flutter doesn't figure out this properly.
Any ideas?
Try to store data to local storage or sqlite for persistence data.