Rive is a very useful animation tool that can create beautiful animations and we can add these in our Application. In flutter, we can add animations by writing so many lines of code but this is not a good practice for a developer. Instead of writing lines of code to create animation, we can create one using this powerful Rive animation tool. Please read all the below points in sequence to understand the topic clearly.
- Create a new Flutter application using command Prompt. For creating a new app, write flutter create YOUR_APP_NAME and run this command.
- Open the app in VS Code or in Android Studio. I am using VS Code.
- Delete the default code from main.dart file for now.
- Now to create new animation go ahead to https://rive.app/explore/popular/trending/all .
- You can also export animations that were created by some other users. Click any animation and Click “Open in Rive”. Then download it by clicking the export button.
- The file extension should be .flr and format should be Binary.
- Now, open VS Code and create new folder “assets” in the root directory of the application and paste the files which you have downloaded from rive. I have 4 files in the assets folder.
-android -assets -my.flr -teddy.flr -test2.flr -test3.flr -build -ios -lib -main.dart -test -web -pubspec.lock -pubspec.yaml -README.md -rive_flutter.iml
- Now, edit pubspec.yaml file :
- Add rive in dependencies :
- Add assets in flutter:
- After that, open main.dart file as we are going to write the code in this file.
- Delete all the code from the main.dart file and write the below code to add animations to our application.
- We will display these animations on our Home Screen. Don’t forget to give the type of animation in FlareActor Widget otherwise, you will not get any animation effect.
- Run the app by writing command flutter run in terminal and see the output.