Open In App

Rive animations in Flutter

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. 

Steps:



-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






import 'package:flutter/material.dart';
import 'package:flare_flutter/flare_actor.dart';
  
void main() => runApp(MyApp());
  
class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'GeeksforGeeks',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: MyHomePage(),
      debugShowCheckedModeBanner: false,
    );
  }
}
  
class MyHomePage extends StatefulWidget {
  @override
  _MyHomePageState createState() => _MyHomePageState();
}
  
class _MyHomePageState extends State<MyHomePage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text("GeeksForGeeks")),
      body: Container(
        child: ListView(
          children: <Widget>[
            Padding(
              padding: const EdgeInsets.all(8.0),
              child: Container(
                width: 700,
                height: 300,
                child: FlareActor(
                  "assets/test3.flr",
                  animation: "day_and_night",
                ),
              ),
            ),
            Padding(
              padding: const EdgeInsets.all(10.0),
              child: Container(
                width: 700,
                height: 300,
                child: FlareActor(
                  "assets/my.flr",
                  animation: "left2right",
                ),
              ),
            ),
            Padding(
              padding: const EdgeInsets.all(8.0),
              child: Container(
                width: 700,
                height: 300,
                child: FlareActor(
                  "assets/teddy.flr",
                  //test, success,idle,fail
                  animation: "success"
                ),
              ),
            ),
            Padding(
              padding: const EdgeInsets.all(8.0),
              child: Container(
                width: 700,
                height: 300,
                child: FlareActor(
                  "assets/test2.flr",
                  animation: "Demo Mode",
                ),
              ),
            ),
          ],
        ),
      ),
    );
  }
}

Output:

Complete code is available on  https://github.com/singhteekam/rive-flutter


Article Tags :