Using hero animation with GetX Flutter - flutter

Does anybody have experience using the Hero animation with the GetX Route-Managment? I followed the instructions in https://docs.flutter.dev/development/ui/animations/hero-animations and use Get.toNamed()to navigate between my routes but it doesn't work.

I've been using Getx for quite some time, and I don't suggest trying to get the hero animations with Getx's route manager, because the Hero widget can link two widgets with the same tag using a HeroControllerScope, which is an InheritedWidget.
the InheritedWidget can be found in a place by the BuildContext where it's looked up.
and Getx break this rule, the Get.to() and Get.toNamed() navigate to new screens using a pre-set BuildContext.
so this will only get you into trouble, instead, think about using the Navigator widget with a BuildContext, to get Hero animations executing fine.

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 and Flame, how to keep FlameGame widget alive?

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.

Why use BloC or Provider in Flutter when we already have Flutter's built-in setState?

Maybe I don't understand the purpose of BloC or Provider but I'm confused as to why we would ever want to use them instead of using Flutter's built-in state management using the Stateful widget. I've just finished an app and can't remember a point where I wished I needed something more than the defaults. Can anyone clear things up for me?
There are a few reasons to use a BloC or Provider rather than Flutter's built-in setState:
BloC and Provider offer a more robust way to manage state.
BloC and Provider make it easier to update state across multiple widgets.
BloC and Provider can be used to manage async data.
BloC and Provider offer a more modular way to structure your code.
There are some case that you need BLoC to make you easier to define each state or condition that happening inside the application.
We will start discussing creating app like https://www.tokopedia.com/ (inspect element and go with phone size preview). You will see that between widget section tokopedia_ss there are some loading animations, and when the data load complete the widget loading animation changed to viewable widget (as user).
in bloc, you will make stateLoading(), stateComplete(data), stateFailed(data). and in the controller or screen you can describe what will happen when bloc state is stateLoading etc...
Creating this case with setstate is more complicated and make your code messy, also setstate will make phone render all the Build() code. not like BloC builder, you can define each widget or section.
So, when there are 10 sections, using Bloc you able to make it render each state but when using standard setstate it will render all the 10 sections in one time every state changes.
More information about BloC: article_about_BloC

Building specific Navigation animation with Flutter

Is there a way to build such an effect with Flutter by navigate from one page to another?
Do you have an idea to build an effect like that? I would post code examples, but I really have no idea how to do anything like this...
I think the navigations between those pages are the Hero Animations.
As for another transition, you can use this package.
I hope it will help you.
You can Hero Widget to achieve this.
In the first screen wrap your image with Hero widget and provide it with a tag.
In the second screen wrap your image with Hero widget and provide it with the same tag.
Hero(
tag: 'firstImage'
child: Image.asset('images/1.png'),
)
You can watch the Hero widget video in the Flutter widget of week https://www.youtube.com/watch?v=Be9UH1kXFDw&feature=emb_logo.
To read more about the hero widget, you can checkout https://flutter.dev/docs/development/ui/animations/hero-animations.

Flutter: Using Hero without Navigation

I have an app that uses a BottomNavigationBar to switch between two screens with their own navigation stack. I would like to use the Hero tag to create a custom transition between the two, but since I don't use navigation, but rather change the state to switch between screens, I'm not sure if this is possible at all.
Is there any way to recreate the transitions provided by Hero without using Navigator?
The Hero widget is not what you are looking for. Try the animations package made by the flutter team. Here the link to this package.
Is not easy to use, but get a try, or you can use the default Navigation built in.