The ball should never stop, and it should bounce at the edges of the available space. What we see as bouncing is actually a change in direction. So when the ball meets the right-hand edge, it should move left, and vice versa. The same is true for the vertical direction when it moves up. The ball should change direction and move down when it meets the top border. Also, the animation value wouldn't be useful, so we need to separate the ball position from the animation value, and use the animation only as a way to redraw the ball in the correct position. Let's look at the steps to apply this logic:
- In the pong.dart file, first, let's create an enum for the directions, under the import declarations, as shown here:
enum Direction { up, down, left, right }
In case you've never seen it before, the enum keyword creates an Enumerated type. This...