I'm trying to transition a Text Widget between two screens (using Hero widget).
I'd like the Text Widget to change its style between these two screens (let's say FontSize).
Implementing it resulting in a strange behavior: the text doesn't change its size smoothly but rather has jerky animation...
Any idea on how to implement it correctly?
recently, I published a Package HERO_TEXT
https://pub.dev/packages/hero_text
it seems to me that it can help you.
Related
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.
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.
If we implement any chart ( whether it be a Linechart or Barchart from chart_flutter ) and in behaviours we have added charts.PanAndZoomBehavior(), pan and zoom behaviour is working fine when it is added in a screen without a scrollview
Here is the scenario Widget hierarchy as
SingleChildScrollView -> charts.LineChart
In gesture arena only SingleChildScrollView gesture is winning, Pan and zoom Behaviour is not working google/charts google/charts#677
This article is helpful https://medium.com/koahealth/combining-multiple-gesturedetectors-in-flutter-26d899d008b2
Does any one know what can be a better approach for this
I believe that is because you need to wrap the Chart Widget that is inside some other widget that has physics (property) in it.. The charts itself doesn't have any physics defined. It's managed using states model references.. I had this problem a long time ago too.. Here's my recommendation (with very amateurish knowledge on flutter):
First, I would wrap my charts within a card widget.
Second, I would avoid using SingleChildScrollView. Unless you are absolutely certain what widget you are building under that parent and they each have Intrinsic sizes defined within the child widgets. I would highly recommend using CustomScrollView -> And add a simple SliverChildBuilderDelegate. That lazily builds your charts (now wrapped in a card/container/column.. anything you chose).. That way you don't have to worry about sizes and scrolling. And any children that you add gets lazily built when they scroll into viewport..
I would like to have a tab bar that looks like this:
Note the center "My ID" button.
So here is my main problem:
Obviously I need a SafeArea to deal with irregular shaped screens, which itself need to be embedded in a Container so I can give the bar its background color. But, by doing this, how can I create the "oversized" button at the center?
After spending several hours banging my head against the wall, found a not so elegant solution. (Hey, but it works)
Here's a picture of the result.
So the way I made it work is actually by having two layers.
On the base of the widget tree is a Stack which contains everything that is currently seen on this page.
The actual bar widget has the text and icons, (the My ID part has only text no icon, but a placeholder SizedBox is used in place of the icon otherwise would be there)
By using the stack, I am able lay the round icon on top of the entire bar much like a FloatingActionButton
I want users to scroll between pages in PageView, but I don't want to show them an animation when they try to scroll before first and after last page. I can switch between colorful animation, black animation and no scrolling, but I could not find any possibility to disable the animation at all.
If there is no such possibility, how can I change the color of that animation or make it transparent at least?
Based on your screenshot, I can say that you are using BouncingScrollPhysics for your PageView. This behavior is commonly used by iOS devices. Nonetheless, I have also reviewed the entire source code you have provided here.
What went wrong
You have added PageView without accompanying it with a Scaffold or Material widget at the top level that's why the background behind the children of the PageView is color black.
https://dartpad.dev/c709e410d0a68248ac5b387b3bc6af93
From the documentation:
Scaffold implements the basic material design visual layout structure.
Without this widget, you'll notice that your app may occupy the entire screen of your device, including the notification bar, because it (PageView) does not know where is the status bar is located in the screen.
What you can do
I noticed that all of the children added inside the PageView has individual Scaffold and AppBar, it's not really necessary to nest scaffolds and you may want to use TabBarView instead of PageView, and let the parent widget handle the AppBar changes via TabController.
But if you think it'll cost you too much effort to refactor, feel free to review the following options that require minimal changes which will suit your needs:
Option 1. You can wrap your widget inside a Scaffold widget.
https://dartpad.dev/4620ff91444353f5e000d2063594bd96
Option 2. Given that nesting Scaffold widgets is not a good practice, you can just use the plain Material widget to wrap your PageView with children wrapped with Scaffold widget.
https://dartpad.dev/43f8730e5592ce1f96193fc01f08a29c
These solutions will change the background color of the PageView from black to white.
Option 3. If you really want to get rid of the animation, the easiest way to hack it is changing your scroll physics:
physics: ClampingScrollPhysics(),
However, this still has a glowing or ripple effect when you try to swipe at the end of the screen.
To further get rid of this effect, I'll share with you these SO answers:
How to remove scroll glow? (works for Android)
How to remove overscroll on ios? (works for iOS)
Further reading
https://api.flutter.dev/flutter/widgets/ScrollPhysics-class.html
https://medium.com/flutter-community/custom-scroll-physics-in-flutter-3224dd9e9b41