How expensive are videos in Flutter? - flutter

Normally, if a widget has to rebuild many times or requires a lot of GPU resources, it is expensive. So, how about videos?
For example, consider the two following scenarios:
A screen with a black star shape (made of a widget like ClipPath or similar) animated on the screen.
Exactly the same thing as item 1, but instead of the star being made with a widget, the screen is actually a full screen video of a black star being animated.
Which alternate would probably be more expensive?
I know this is a broad question, but having a sense of what approaches are relatively costly would be very useful. I’m not very knowledgeable about the deep workings of Flutter, so I’m hoping someone could give me a better sense about the costs of videos.

Widget rebuild is very fast and not expensive. It is intended be to rebuilt very frequently. You can rebuild and animate hundreds of widget every frame without lagging.
Video player are implemented in native language, and the performance are very different on different devices
For simple animation, you should use widget, using video won't improve performance, but for very complex animation or 3D animation, using pre-rendered video could be useful

Related

How to do trajectory animation in Flutter?

I'm looking for trajectory animation just like how https://leo9studio.com/ has done. You see while scrolling, those balls get scrolled from top to bottom. How can we replicate exactly in Flutter Web?
Additionally, how to create such a smooth scrolling effect in Flutter?
rive.app would be a good place to start looking, since you aren't really providing any context or code other than just a random idea, they have a great community and I have used their packaged for some neat animation on my web apps. They have a way to create your own designs and animations which would probably be the case there, unless you wanted to make it all with code then that would be a different story.
Or look at this post here How to animate a path in flutter?

Is it possible to not reuse child widgets in using Flutter's AnimatedList?

I'm working on a Flutter app that has features similar to whatsapp where there can be a bunch of messages that are essentially audio players. I'm using AnimatedList so the chat bubbles animate in and out.
The issue is it doesn't seem that AnimatedList supports keepAlive and I haven't come across any alternatives. I don't want the widgets to be recycled because if a message is playing and I scroll the message in and out of view, I want the message to keep playing AND animating and right now I instantiate an audio player and animation controller in each child widget. I could see this being more "optimal" if I maintained all this state outside of the child widgets (at the same level as the list) but the max amount of chat bubbles per conversation in this app is ~50 and we want to move fast instead of be optimal right now so I think this simplification is a good idea if I can keep the widgets alive.
I tried wrapping the child widgets in a KeepAlive with no luck. Below seem like my options:
There is some supported way to do this and I'm not aware of it
There is some alternative / 3rd party lib that supports this
Try using a non animated list and explore other ways to animate
Implement the state above the children
I'd be curious to hear of potential solutions from the community. Thanks!
All the proposed solutions are fine (the fourth is probably the most reliable if you need it to work quickly but not the most efficient for sure...).
Did you think about using one InheritedWidget that you would place above your animated list, which would control the audio player. (I am assuming that you only want one audio playing at a time).
So concretely, you would have an inherited widget that would expose a start(File file) method and a pause(File file) method and the duration property and a unique identifier for the current message being played. This would allow you to keep your state structure simple and still be quite efficient.
I can write a piece of code if my explanation is not clear enough .

Circle/wheel ScrollView in Flutter

I'm having a hard time finding a widget I need in Flutter, which I thought wouldn't be that rare.
What I'm looking fore is something very similar to this:
Which is available at pub.dev, but doesn't have the flexibility I'm looking for.
Ideally, the widget I'm looking for wouldn't end like this one (when you keep scrolling it would go back to the first element). Also, I intend on stacking concentric wheel ScrollViews with different diameters.

How to Have Lots of Moving Widgets in Flutter App

I know there are game/sprite engines written for Flutter, but my goal is to better understand painting and widgets, so I want to do this myself.
If I wanted a bunch of small widgets that could move around on a gameboard, what would be the best way to do this? Would I just create a box widget with fixed dimensions and have a bunch of children where I could control their position?
One example would be having a playing area with scrabble tiles that could be moved around. Or Tetris blocks falling. Different widgets that can be anywhere and that can be moved. I'm just looking for someone to point me in the right direction. Thanks.
You can draw custom shapes and lines using canvas in flutter and then animate them as flutter supports 60 frames per second. You need to understand customPaint very well. Here is a great demonstration of how to use customPaint to draw custom shapes.
https://medium.com/#rjstech/flutter-custom-paint-tutorial-build-a-radial-progress-6f80483494df

How to code smooth scrolling for "flick" gesture on iPhone

I have horizontal list for which I'm implementing my own scrolling logic. I have the "touch and drag" scrolling working great, but I'm having trouble with the "flick" gesture. All the built in scrollable views have the feature that if you "flick" the view it scrolls faster or slower based on the intensity of the flick.
Does anyone has any suggestion how do that for my view?
What I'm doing right now is changing the UIView.center.x coordinate of my custom UIView to scroll it across the screen
I would strongly suggest you figure out how to make use of the built in UIScrollView class. Apple has invested a LOT of effort to make scrolling feel 'right'. You may be able to recreate some, or even all, of that feel, but it'll take a lot of work. Better to piggy back off of what's already been done.
If you want to implement your own scroll view, you'll have to make the view scroll based on the length of the sweeping distance and the speed at witch it went across the screen. Taking these parameters as input and using simple geometry math you could calculate how much further the view should scroll after the sweep has ended(touchesEnded event).
Ofcourse this is not as simple as it sounds, making the flick gesture just feel right and natural is much harder.
If you really are set on doing this yourself, Drew McCormack has a great article on MacResearch where he explains some of the physics behind momentum-based scrolling. His implementation uses HTML, CSS, and JavaScript, but the core principles could be brought across to your custom UIView subclass.