I have been searching around for days in the jungle of widgets, trying to figure out which widget suits my purpose best.
What I have done so far: I have a Positioned widget with a listener, that I can drag around in a Stack with onPointerMove.
What I want to achieve is the following:
If I move my finger a bit faster and at some point let go, I would like to have the widget to continue with the given speed (with some friction) and direction (x,y) until it reaches some point.
Im a iOS developer and did this in Swift, but have I reached a point where I met the limit of Flutter?
Flutter has a Draggable widget which contains velocity in the onDragEnd event. You might use this and some basic animation to fling the widget using physics. Check out the Cookbook on the Flutter API site.
Related
Currently in the design phase of an app. One of the goals we have is to be able to touch a certain widget, and on tap and hold, have the widget then follow the user's finger where they drag.
Then, if the user releases gently, the widget snaps back to the original location.
However, if the user flicks the widget, we want the widget to fly across the screen, reacting correctly to the user's flick.
Is there anything built-in that can handle this? Also, if this needs to be explained more to make sense, happy to elaborate.
Thanks!
I think for such cases you can use GestureDetector widget. It provides several useful functions. See here:
https://api.flutter.dev/flutter/widgets/GestureDetector-class.html
You can use onPanStart of GestureDetector and then get the offset and use it to move the widget accross the screen.
I am looking for way to implement wraparound widget in flutter. I need to create screen which space will be finite but unbounded, In other words I want to do something like when widget1 leaves the side of the screen it have to reappear on the opposite side immediately. I have stack and thanks to positioned I am re-rendering new position of widget based on accelerometer.
I don't know where to even start looking, if there is some package for it or should I implement it from scratch?
Please have a look at the package carousel_slider
https://pub.dev/packages/carousel_slider
It also features infinity scrolling which should provide the effect you want.
So basically I want to make a widget that checks how much space is available and if there is not enough space to wait a few seconds and then slowly glide and stop at the start position. This process should repeat forever and optimally don't use too much performance. If did not get a clear idea of how I want the widget to behave, just look at the Spotify song names.
You can use an AnimationController with a custom animation which moves a Positioned widget containing the Text widget to make your own ScrollingText widget. There's another question where this exact problem gets covered in more detail. You can just copy-paste the code from there and you should be good.
Basically I'm trying to build a game to learn flutter more.
Right now I'm just trying to get a Text widget to move from the top of the phone screen, towards the bottom of the phone screen... I'm building a Space Invaders type of game with just Text.
From what I've read by googling the problem, should I use Flame? Or can everything be done by just using the base Flutter framework (collision detection, moving widgets, etc...)? Thanks.
You can use Draggable class for dragging the item.
A simple way to solve this problem is to have the moving Text widget a child of the Stack() widget. Actually, the child of the Stack() widget is a Positioned() widget, which has left and top properties, which you can update periodically with a Timer.periodic function to move the widget down by incrementing top property. So, your Text widget is a child of the Positioned() widget, that you use for, well, positioning.
I have a working example of this in my slowly_moving_widgets_field project, where I have a bunch of arbitrary widgets moving about the screen every X seconds as you desire.
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