Building implicit animations using Flutter’s animations package
Now that we have learned how to leverage implicit and explicit animations, let’s refactor our code to take advantage of Flutter’s animations
package, which contains pre-canned animations for common use cases from the Material motion system spec.
First, install the animations
package by running flutter pub add animations
in the project’s root directory in the terminal.
Next, swap out AnimatedSwitcher
in excuse_page_view.dart
with PageTransitionSwitcher
from the package. The PageTransitionSwitcher
is a variation of the AnimatedSwitcher
that allows for separate transitions to be used for the entry and exit animations. Replace the build
method of ExcusePageView
with the following code:
final selectedExcuse = excuses[currentExcuse]; return PageTransitionSwitcher( duration: const Duration(milliseconds: 500), transitionBuilder: ...