In this recipe, you will refactor the animation, adding a curve and changing the movement so that it takes all the available space:
- At the top of the _ShapeAnimationState class, add two new double values for the maximum value for the top coordinate and the maximum left coordinate, a new Animation of type double (animation may already exist if you didn't delete it in the previous recipe), and a final int containing the size of the ball:
double maxTop = 0;
double maxLeft = 0;
Animation<double> animation;
final int ballSize = 100;
- In the build method, enclose the Stack widget in a SafeArea with a LayoutBuilder. In the builder, set the maxLeft and maxTop values to be the constraints max values, minus the size of the ball (100). The left and top values of the Positioned widget will take posLeft and posTop. The full body of the Scaffold is shown here:
body: SafeArea(child: LayoutBuilder(
builder: (BuildContext context, BoxConstraints constraints) {
maxLeft =...