I need a listView for my Game. Is there a simple way to create one? There are no tutorials for such a feature and I couldn't find anything in the documentation.
Flame doesn't provide their own widgets for these things, we rely on Flutters excellent widget system.
So you create the widget directly in Flutter and then you either put your GameWidget in a stack (or similar) and use Flutter's own Navigation to move between the widgets, or you use Flame's overlay system.
For using the overlays you add the overlays that you want to have accessible when you create the GameWidget and then you call game.overlays.add to render a specific widget, and game.overlays.remove to stop rendering it.
Related
I am learning and playing around with Flutter. Currently I am trying to reproduce an app I previously made with C# and WPF. In my Flutter app I have a list of Widgets extending CustomPainter. Now I am able to move/drag any of these widgets around the screen. What I see is that always when dragging one of this widgets all CustomPaint widgets are repainted. I checked what would happen if I decide to resize my window, and you can guess, all CustomPaint widgets are repainted.
I decided to create three different projects. One is using statefull widgets and setState to manage the state. The other is using Provider and the last one is using Riverpod. Still all Widgets extending CustomPainter are repainted when dragging a single Widget or resizing the window.
Now my question is, am I doing something wrong in my state management or is this behavior by default?
Also my C#/WPF app uses half the cpu the Flutter app uses when dragging one shape around. I did not expect such a difference. For now I did not make any complex CustomPaint obecjt in my flutter app. But should I expect a big performance reduction if I have many complex CustomPaint widgets?
am I doing something wrong in my state management or is this behavior
by default?
Yes and no. Widgets are rebuilt when the screen size changes, but dragging a widget should not make other widgets rebuild. You can try RepaintBoundary (https://api.flutter.dev/flutter/widgets/RepaintBoundary-class.html)
Should I expect a big performance reduction if I have many complex
CustomPaint widgets?
This has a lot to do with what kind of CustomPaint widgets you will be using and what is "many". You can test how long the CustomPaint widget's paint method takes, for example by using the profiler (https://docs.flutter.dev/perf/ui-performance). My assumption is that the efficiency decreases linearly as you add more CustomPaint widgets
The panorama package on pub.dev only works with Image objects, but the premise should be the same if a video is used instead.
I want to modify this package to accept a VideoPlayer or VideoPlayerController widget from the video_player package. What are the things I must do to make it compatible?
The way panorama works is it takes the Image object and passes it to the package flutter_cube where it then makes a Mesh and texture out of it. The panorama viewing is done based off of this.
What I want to achieve is instead of Panorama accepting an Image widget, it should be the VideoPlayer widget. Width and height are really the only two variables needed so I wonder what I should do, those two are easily obtainable from the VideoPlayerController.
Can Flutter Flame render Widget inside game world like other components? (not overlay widget).
(I want to apply forge2d physic to widget and I'm trying to do it with Flame.)
You can not, you can only do it through the overlay system or use a Stack, but the widgets are never "in" the game, but on top of the game.
The game can only have Flame Components added directly to it.
You can still interact with the overlay widgets from the game though, like this for example: https://twitter.com/spydon/status/1417832832693673988
In that example I simply wrap the ElevatedButton with Positioned and Transform and then I updated those with the values from corresponding BodyComponents.
I am developing a game with flame engine. I need to open a text input (textField, textEdit or whatever its name) and ask the user his/her input (player name) as a text in my flame game. How can I do that in flame?
There are two ways to go about doing this:
The first option is to build it yourself. This might allow for the most possible level of customization, and would involve creating a TextBoxComponent and listening to KeyboardEvents on your game. You would need to implement rendering and commands like moving the caret by yourself.
The easier option is to use the widgets overlay feature. Remember that the Flame game is just another widget in the tree, and you can compose widgets using the Flutter Stack widget. With widgets overlay you can more easily add a component that hovers on top of your flame game, that you can use to add your text input. I recommend building a simple Flutter Container with all the text input fields and labels you need and using a Widget Overlay to position that on top of your game. Please read the docs for Widget Overlay for more details. Also be sure to check out a list of all the other flame-provided widgets other than GameWidget that you might want to compose with your Flutter tree.
When you swipe vertically, image is dragged towards the swipe, with fading out animation of black background.
And after release, it smoothly returns to it's previous position on the screen, like Hero animation does.
How is it possible to recreate such an effect using Flutter? The same scenario, in fullscreen photo view.
photo_view package is desired for fullscreen, so it shouldn't interfere with zooming.
What you need is actually an out-of-the-box widget, and it's surprisingly easy to use. It's called Hero. Basically, you wrap the widget you want to animate like that in a Hero widget, with a specific tag string, and, when you navigate to another screen, you wrap the destination widget in another Hero with the same tag. An effect like the one you shared can be achieved by wrapping two widgets with the same photo with Heroes in different PageRoutes.
Check out this Flutter widget of the week video to get you started, and this Flutter.dev article for a more detailed explanation on Hero widgets.
Edit: I see you are looking for a more specific image-viewer behavior. Then, I suggest you use the photo_view package, which includes many functionalities to visualize images, including the hero transition with swipe-dow-to-dismiss behaviors, pinching to zoom, etc.
I found the solution.
To create such an animation, you should use extended_image package, which has SlideOutPage widget for creation of such transitions.